Hello, I was trying to draw 60000 planes using a job in Unity 6 Preview, HDRP.
However, the planes are only shown in the editor scene view, not in-game.
Additionally, the performance hit is massive and comparable to my previous technique using managed code (UnityEngine.Graphics.DrawMeshInstanced).
Please let me know if there is anything wrong with my code. Thanks.
...
unsafe
{
fixed (Pathing.Node* nodesPtr = Pathing.Nodes)
{
var builder = DrawingManager.GetBuilder(true);
var job = new DrawingJob
{
Builder = builder,
Nodes = nodesPtr,
NodesLen = Pathing.Nodes.Length,
ActualNodeScale = Pathing.ActualNodeScale,
DebugViewHeight = DeveloperUiBehaviour.DebugViewHeight,
}.Schedule();
builder.DisposeAfter(job);
job.Complete();
}
}
...
[BurstCompile]
unsafe struct DrawingJob : IJob
{
[NativeDisableUnsafePtrRestriction] public Pathing.Node* Nodes;
public int NodesLen;
public float ActualNodeScale;
public float DebugViewHeight;
public CommandBuilder Builder;
public void Execute()
{
Builder.PushColor(Color.white);
for (int i = 0; i < NodesLen; i++)
{
var node = Nodes[i];
if (node.IsHardObstacle)
{
continue;
}
TransformDataFromNode(node, out var position, out var rotation, out var scale);
Builder.SolidPlane(position, rotation, scale);
}
Builder.PopColor();
Builder.PushColor(Color.red);
for (int i = 0; i < NodesLen; i++)
{
var node = Nodes[i];
if (!node.IsHardObstacle)
{
continue;
}
TransformDataFromNode(node, out var position, out var rotation, out var scale);
Builder.SolidPlane(position, rotation, scale);
}
Builder.PopColor();
}