Performance: Panel and layout groups
MEDIUM IMPACT
This affects how quickly the UI elements are arranged and rendered on screen, impacting frame rate and responsiveness.
GameObject panel = new GameObject("Panel"); var verticalGroup = panel.AddComponent<VerticalLayoutGroup>(); // Add simple children without extra LayoutGroups or ContentSizeFitters for (int i = 0; i < 50; i++) { GameObject child = new GameObject($"Child{i}"); child.transform.SetParent(panel.transform); // Use fixed sizes or minimal layout components }
GameObject panel = new GameObject("Panel"); panel.AddComponent<VerticalLayoutGroup>(); // Adding many child elements each with their own LayoutGroup for (int i = 0; i < 50; i++) { GameObject child = new GameObject($"Child{i}"); child.transform.SetParent(panel.transform); child.AddComponent<HorizontalLayoutGroup>(); child.AddComponent<ContentSizeFitter>(); }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Nested LayoutGroups on many children | High (many GameObjects with LayoutGroups) | 50+ per frame | High (many recalculations) | [X] Bad |
| Single LayoutGroup on parent panel | Low (one LayoutGroup) | 1 per frame | Low (minimal recalculations) | [OK] Good |