When to use static GameObjects?

I have some questions, which may seem trivial to some, I searched the web but I did not find anything exhaustive.

I have to optimize my project on Unity, my project is in 2D made with UI objects (so “Image” component and “Canvas Render” component in the same object), I have to mark the objects as “Static”, I understand that an object is static when it is not moving in the scene, but there are other cases that I don’t have clear ideas:

  1. Is an object static when it has the “CanvasGroup” component and the “alpha” value changes at runtime?

  2. When I have a Menu with many screens placed side by side, and the Camera moves sideways between the screens, are the various screens static objects? Or since the Chamber moves, aren’t they?

  3. If an object is activated and disabled at runtime, can the object be marked as a static object?

  4. If a UI object has a scrollable “RectTransnform” based on the Device Display Width and Height, can the object be marked as static?

  5. If a UI object could be covered by another object, can the object be marked as “Static”?

Thanks for your attention

I’ve never bothered marking UI as static. Not even sure why that would matter or help. The reason: Unity is already really good at identifying things that don’t need updating, and that’s all that marking something static does really. It’s more for particular subsystems that need it.

Static is also not just a single flag. Static can mean any number of things:

7027363--832507--Screen Shot 2021-04-11 at 10.34.56 AM.png

In the Unity documentation, it says that marking static objects potentially improves performance.
https://docs.unity3d.com/Manual/StaticObjects.html

You should start setting the GameObjects to “Static”.

1 Like

I prefer to attach the Profiler (Window → Analysis → Profiler) rather than blindly following “potentially” type guidelines.

This is the first time I’ve even heard of marking UI static… I don’t even know what that could possibly do in the UI. If you are familiar with the UnityEngine.UI objects, a) they don’t use MeshFilters or MeshRenderers, and b) they produce and live-generate geometry all on the fly based on anchors, layout controllers and RectTransform relations and everything else related to sizing.

Besides, most optimization suggestions for Unity UI that I have seen involves restructuring your UI to reduce Transform updates, reduce overdraw, reduce drawcalls and take advantage of sprite atlases.

But none of that matters unless you attach the profiler and find out what’s actually costing you so much performance. Start there.

1 Like