Layered Grid Graph Scan & Gizmo Performance

Using version 4.2.18, I have a layered grid graph of a pretty significant size (1000x1000) so I realize this is quite possibly just a consequence of that.

But the performance in the scene view from just rendering all the gizmos for the grid squares is pretty rough–just shy of unusable. Is there any way to improve this? The gizmos are mighty helpful for debugging. Most scenarios I test on a much smaller grid but this larger size isn’t even necessarily the largest I expect the game to get to.

The actual pathfinding performance is totally great/fine within game. The scan, however, can take quite awhile. I am using this scan a terrain specifically of pretty significant size.

The functionality of the grid graph works very well with the type of game (a city builder) where much of the logic is broken down into a grid as well and we need per-cell modifications to the movement of agents. This is a 1:1 match with the grid graph and I’m hoping to keep this working but moving to a navmesh (and using cutouts for the buildings in the city) is an alternative if need be.


Try the beta version. Gizmo drawing should be faster there :slight_smile: Scanning should be faster too!

Thanks for the speedy reply!

I’ve tried the beta update–happy to report scanning is indeed significantly faster.

However there’s still a pretty significant slowdown on the gizmos drawing in the scene view.

If I disable “Show Graphs” entirely via the widget int he lower right of the scene view everything is fine. However if I turn off all the toggles in the inspector of the Pathfinder component despite nothing being rendered it’s still quite slow (something in memory maybe?).

I think I saw somewhere in another forum thread maybe that 1000x1000 grid is reaching pretty far for what you may have intended? If that’s the case then I might just need to rethink my usage here entirely (and maybe go to a nav mesh).

After a bit of time these errors did start popping off in the console every update if it helps any:

Assertion failed
UnityEngine.GUIUtility:ProcessEvent (int,intptr,bool&)
ArgumentNullException: Value cannot be null.
Parameter name: value
UnityEngine.MaterialPropertyBlock.SetTexture (System.Int32 nameID, UnityEngine.Texture value) (at <c2d036c16ca64e0eb93703a3b13e733a>:0)
UnityEngine.Rendering.Blitter.BlitTexture (UnityEngine.Rendering.CommandBuffer cmd, UnityEngine.Rendering.RTHandle source, UnityEngine.Vector4 scaleBias, UnityEngine.Material material, System.Int32 pass) (at ./Library/PackageCache/com.unity.render-pipelines.core@14.0.8/Runtime/Utilities/Blitter.cs:261)
UnityEngine.Rendering.Universal.Internal.CopyDepthPass.ExecutePass (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.Internal.CopyDepthPass+PassData passData, UnityEngine.Rendering.CommandBuffer& cmd, UnityEngine.Rendering.Universal.CameraData& cameraData, UnityEngine.Rendering.RTHandle source, UnityEngine.Rendering.RTHandle destination) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/Passes/CopyDepthPass.cs:186)
UnityEngine.Rendering.Universal.Internal.CopyDepthPass.Execute (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.RenderingData& renderingData) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/Passes/CopyDepthPass.cs:103)
UnityEngine.Rendering.Universal.ScriptableRenderer.ExecuteRenderPass (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.ScriptableRenderPass renderPass, UnityEngine.Rendering.Universal.RenderingData& renderingData) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/ScriptableRenderer.cs:1490)
UnityEngine.Rendering.Universal.ScriptableRenderer.ExecuteBlock (System.Int32 blockIndex, UnityEngine.Rendering.Universal.ScriptableRenderer+RenderBlocks& renderBlocks, UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.RenderingData& renderingData, System.Boolean submit) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/ScriptableRenderer.cs:1446)
UnityEngine.Rendering.Universal.ScriptableRenderer.Execute (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.RenderingData& renderingData) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/ScriptableRenderer.cs:1222)
UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderSingleCamera (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Rendering.Universal.CameraData& cameraData, System.Boolean anyPostProcessingEnabled) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/UniversalRenderPipeline.cs:650)
UnityEngine.Rendering.Universal.UniversalRenderPipeline.RenderSingleCameraInternal (UnityEngine.Rendering.ScriptableRenderContext context, UnityEngine.Camera camera) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/UniversalRenderPipeline.cs:534)
UnityEngine.Rendering.Universal.UniversalRenderPipeline.Render (UnityEngine.Rendering.ScriptableRenderContext renderContext, System.Collections.Generic.List`1[T] cameras) (at ./Library/PackageCache/com.unity.render-pipelines.universal@14.0.8/Runtime/UniversalRenderPipeline.cs:376)
UnityEngine.Rendering.RenderPipeline.InternalRender (UnityEngine.Rendering.ScriptableRenderContext context, System.Collections.Generic.List`1[T] cameras) (at <c2d036c16ca64e0eb93703a3b13e733a>:0)
UnityEngine.Rendering.RenderPipelineManager.DoRenderLoop_Internal (UnityEngine.Rendering.RenderPipelineAsset pipe, System.IntPtr loopPtr, UnityEngine.Object renderRequest, Unity.Collections.LowLevel.Unsafe.AtomicSafetyHandle safety) (at <c2d036c16ca64e0eb93703a3b13e733a>:0)
UnityEngine.GUIUtility:ProcessEvent(Int32, IntPtr, Boolean&)


Indeed, 1000x1000 is at the upper limit of what I’d recommend. For very large graphs I tend to recommend a recast graph instead.

You can check the unity profiler to see what the slow part is.

The error message doesn’t seem related, from what I can see.

Drilled down int he profiler and it seems ultimately drawing the gizmos in ALINE is what occupies the most time:

I’m going to do the work to transfer over to a navmesh in short order, but maybe there’s something I could do here to improve grid performance anyhow? Happy to get you more details if you want more info for your own development purposes as well.

Ah, yeah. It most of the time in the grid graph’s OnDrawGizmos method, checking if the graph has changed in any way. It’s hard to avoid this, since the graph can change. It avoids re-generating the gizmo mesh if at all possible. Make sure your graph color is set to SolidColor and that you are not drawing unwalkable nodes. This will speed it up slightly.