Skip to main content

Rebuilding UI Layout

If you are using Unity UI Auto Layout components on your UI, you may face problematic situations where the elements are getting stuck in weird positions due to layout not being rebuilt when necessary.

In these cases you can simply callĀ LayoutRebuilder.ForceRebuildLayoutImmediate, which should be able to fix the problem in many scenarios:

// Call this static method with the root of the layout as a parameter. E.g:
UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(GetComponent<RectTransform>());

If your UI consists of complex nested layout groups, sometimes calling the method above more than once have been able to solve the problem.