Polyline not working in Immediate Mode for URP

Avatar
  • updated

Polyline works fine on BiRP for me, but nothing appears for URP. It works fine via the component, but nothing is visible when drawing one in immediate mode.

The IM Monitor reports the polyline material is in use and that its mesh is in the pool (but unused?)

Image 788

I stepped through the Shapes render pass and the draw call looks like its being added to the command buffer.

Image 789


I tried toggling GPU Instancing, reinstalling, restarting, regenerating shaders/materials, changing join mode etc but had no luck.

Here's the simple test script

public class PolyLineTest : ImmediateModeShapeDrawer
{
public override void DrawShapes(Camera cam)
{
using (Draw.Command(cam))
{
Draw.Matrix = transform.localToWorldMatrix;
using var path = new PolylinePath();
path.AddPoint(Vector3.zero);
path.AddPoint(Vector3.up);
path.AddPoint(Vector3.right);
Draw.Polyline(path);
}
}
}
Reporting a bug? please specify Unity version:
2022.3.13
Reporting a bug? please specify Shapes version:
4.3.1
Reporting a bug? please specify Render Pipeline:
URP
Avatar
christian voigt

I have the same problem. Upgrading to 2023.3.0a18 did not help either.

Avatar
Freya Holmér creator

looks like this might actually be a bug with the mesh disposal!

If you want a fix in the meantime - use persistent polylines instead (which are also much more performant)

using Shapes;
using UnityEngine;

[ExecuteAlways] public class DebugPolyline : ImmediateModeShapeDrawer {

PolylinePath path;

public override void OnEnable() {
base.OnEnable(); // <- very important
path = new PolylinePath(); // create once
}

public override void OnDisable() {
base.OnDisable(); // <- very important
path.Dispose(); // delete once
}

public override void DrawShapes( Camera cam ) {
using( Draw.Command( cam ) ) {
Draw.Matrix = transform.localToWorldMatrix;
path.ClearAllPoints();
path.AddPoint( Vector3.zero );
path.AddPoint( Vector3.up );
path.AddPoint( Vector3.right );
Draw.Polyline( path );
}
}
}

Avatar
christian voigt

thanks for the fix!