Draw.Polyline not rendering in edit mode

Avatar
  • updated
  • Fixed

Immediate mode Polyline isn't rendering in edit mode even when set to [ExecuteAlways].

using System.Collections;
using UnityEngine;
using Shapes;

[ExecuteAlways]
[RequireComponent(typeof(Quad))]
public class Outline : ImmediateModeShapeDrawer
{
[SerializeField] float thickness = 0.15f;
[SerializeField] Color color = Color.white;
    [SerializeField] PolylineJoins joins = PolylineJoins.Miter;

    private Quad quad;

    public override void DrawShapes(Camera cam)
    {         if (quad == null)
            quad = GetComponent<Quad>();

        using (Draw.Command(cam))
        {
            using (var p = new PolylinePath())
            {
                for (int i = 0; i < 4; i++)
                    p.AddPoint(transform.TransformPoint(quad.GetQuadVertex(i)));

                //Only works in play mode
                Draw.Polyline(p, true, thickness, joins, color);

                //Works in edit and play modes
                Draw.Line(p[0].point, p[1].point, thickness, color);
            }
        }
    }
}
Reporting a bug? please specify Unity version:
2021.1.21f1
Reporting a bug? please specify Shapes version:
4.1.0
Reporting a bug? please specify Render Pipeline:
URP
Pinned replies
Avatar
Freya Holmér creator
  • Answer
  • Fixed

this has now been fixed in 4.1.1

Avatar
Freya Holmér creator
  • Under Review

since this works in the built in RP, I suspect this one might take a while to fix :(

A workaround for now is to always cache your polyline/polygon paths in OnEnable, which, as a bonus, is also more performant than creating it on the fly:

using UnityEngine;
using Shapes;

[ExecuteAlways]
[RequireComponent( typeof(Quad) )]
public class Outline : ImmediateModeShapeDrawer {
[SerializeField] float thickness = 0.15f;
[SerializeField] Color color = Color.white;
[SerializeField] PolylineJoins joins = PolylineJoins.Miter;

private Quad quad;

PolylinePath p; // cached polyline path

public override void OnEnable() {
base.OnEnable(); // <- important to keep

// create polyline path on enable
p = new PolylinePath();
p.AddPoints( Vector3.zero, Vector3.zero, Vector3.zero, Vector3.zero );
}

public override void OnDisable() {
base.OnDisable(); // <- important to keep

// dispose polyline path on disable
p.Dispose();
}

public override void DrawShapes( Camera cam ) {
if( quad == null )
quad = GetComponent<Quad>();

using( Draw.Command( cam ) ) {

// edit points here. you can also clear all points and add anew if you want, though this is more performant
for( int i = 0; i < 4; i++ )
p.SetPoint( i, transform.TransformPoint( quad.GetQuadVertex( i ) ) );

Draw.Polyline( p, true, thickness, joins, color );

Draw.Line( p[0].point, p[1].point, thickness, color );
}
}
}
Avatar
Freya Holmér creator
  • Answer
  • Fixed

this has now been fixed in 4.1.1