Split Canvas For Dynamic Objects (Unity)

Split Canvas For Dynamic Objects (Unity)

Symptoms

  • You experience low FPS when using the Unity UI system.
  • You see repeated logs of Canvas.BuildBatch in the Profiler.
  • You need to optimize the UI.

Cause

You have objects in the UI that change the Transform (position, rotation, scale) every frame, which causes a rebuild of the entire UI batch.

Resolution

Separate dynamic objects from static objects.

If you have a large UI hierarchy with one or more objects that move every frame, you should consider separating the dynamic objects to their own dynamic canvas.

When you have objects that change the RectTransform every frame, this causes the canvas to perform a rebuild of the batch. The canvas rebuild process causes CPU spikes.

How to check if you are rebuilding the UI

If you are using Xcode Instruments, look for UI::Canvas::UpdateBatches and Canvas::RenderOverlays on the call stack when you use the Time Profiler tool.

If you are using Unity Profiler, look for Canvas.BuildBatch and Canvas.RenderOverlays.

Non-optimized

Optimized

The images above show the canvas performance with a dynamic object in the same canvas and after being isolated in a new canvas.

If you find that Canvas.BuildBatch is called every frame, you have a UI object that moves every frame.

 

 

Was this article helpful?

Related Articles