Performance: Why everything in Unity is a GameObject
MEDIUM IMPACT
This concept affects how Unity manages scene objects and their rendering performance by structuring all entities as GameObjects with components.
Pre-create GameObjects with required components in the editor or during initialization. Reuse objects via object pooling instead of creating new ones every frame.
GameObject obj = new GameObject(); obj.AddComponent<MeshRenderer>(); obj.AddComponent<MeshFilter>(); // Adding many components dynamically every frame
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Dynamic GameObject creation every frame | High (many nodes) | Multiple reflows | High paint cost | [X] Bad |
| Pre-created GameObjects with pooling | Low (fixed nodes) | Single reflow | Low paint cost | [OK] Good |