Nested UI Layout Problems

How the Check Works

This check examines individual GameObjects within your UI hierarchy. For each GameObject, it checks if it contains a ContentSizeFitter or an AspectRatioFitter. If such components are present, the check proceeds to verify their parent relationships.

The check looks for the following conditions:

  • The presence of ContentSizeFitter or AspectRatioFitter components.
  • Whether the GameObject has an ILayoutIgnorer component and is set to ignore layout.
  • Whether the GameObject is a child of a RectTransform parent with an enabled ILayoutGroup component (such as a LayoutGroup).

If all these conditions are met, it indicates that a ContentSizeFitter or AspectRatioFitter is incorrectly nested within a LayoutGroup. Such nesting can lead to unexpected UI behavior, and the check logs it as an issue.

When to Use This Check

  • UI Hierarchy Cleanup: Ensure that your UI hierarchy is correctly structured to avoid unexpected layout issues.
  • Prevent Layout Bugs: Detect and rectify incorrectly nested ContentSizeFitters or AspectRatioFitters within LayoutGroups to prevent layout bugs.
  • UI Best Practices: Promote adherence to UI best practices by identifying and addressing problematic UI configurations.

How to fix errors like this

You should not have nested layout components in your UI like this. Reexamine the UI you have built and see if you can implement it with fewer components. These components fight against each other to set the size of your objects, resulting in undefined behaviour.

Was this page helpful?