Inconsistent behaviours in UI between polyline component and equivalent immediate drawing

Avatar
  • updated

Heya! 🌸

As discussed on the server, there are some inconsistencies between the polyline component and its immediate drawing equivalent when used for UI.

Reproduction steps

To reproduce the following observations:

  • Add a Canvas to your scene
  • Set its render mode to Screen Space - Camera
  • Add a child Game Object to the Canvas with the polyline componentImage 180
  • Add a child GameObject to the Canvas with a custom polyline script that uses the local matrix and the same inner parameters. Example:
using Shapes;
using UnityEngine;
using ScaleMode = Shapes.ScaleMode;

public class ImmediatePolyline : MonoBehaviour {
    private PolylinePath p;

    private void Awake() {
        Draw.LineThicknessSpace = ThicknessSpace.Meters;
        Draw.LineGeometry = LineGeometry.Flat2D;
        Draw.BlendMode = ShapesBlendMode.Transparent;
        Draw.ScaleMode = ScaleMode.Uniform;
        Draw.PolylineJoins = PolylineJoins.Miter;

        p = new PolylinePath();

        p.AddPoint(new Vector2(-100, -100f));
        p.AddPoint(new Vector2(100, 100f));
    }

    private void OnEnable() => OnPostRenderSubscribe();
    private void OnDisable() => OnPostRenderUnsubscribe();

    private void DrawShapes(Camera cam) {
        Draw.Matrix = transform.localToWorldMatrix;

        Draw.Polyline(p, false,5f, Color.white);
        
        Draw.ResetMatrix();
    }

    private void OnPostRenderSubscribe() {
        Camera.onPostRender += DrawShapes;
    }

    private void OnPostRenderUnsubscribe() {
        Camera.onPostRender -= DrawShapes;
    }

    private void OnDestroy() {
        p.Dispose();
    }
}

Additional notes:

  • It works correctly outside UI
  • I managed to reproduce it with and without URP

Observations

Differences in thickness

The polyline drawn through immediate drawing:

Image 174

The polyline drawn with the Polyline component:

Image 175

Differences in scaling

The immediate-drawn polyline with 0.2 and 3 x-scale:

Image 182

Image 183

The component polyline with 0.2 and 3 x-scale:

Image 179

Image 181

The immediate-drawn polyline's thickness is unaffected by scale changes (while the component polyline's thickness is only affected by scale inferior to 1), also the end caps are oriented differently as a result of the change in scale, see the difference at 3 x-scale:

Image 184

Flat2D Immediate Drawing Polyline tries facing the camera

Same setup from the front:

Image 185

From the side:

Image 186

---

Hope this was clear enough! Have a nice day ✨

Reporting a bug? please specify Unity version:
2020.1.11
Reporting a bug? please specify Shapes version:
2.3.2
Reporting a bug? please specify Render Pipeline: