Performance: Prefabs and reusable objects
MEDIUM IMPACT
This concept affects the initial load time and runtime performance by managing how game objects are instantiated and reused in the scene.
public GameObject enemyPrefab; for (int i = 0; i < 100; i++) { GameObject obj = Instantiate(enemyPrefab); // Modify instance properties if needed }
for (int i = 0; i < 100; i++) { GameObject obj = new GameObject("Enemy"); obj.AddComponent<EnemyBehavior>(); // Set properties manually }
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Manual new GameObject creation | High (100+ new objects) | N/A | High CPU and memory usage | [X] Bad |
| Instantiate from prefab | Low (reuses template) | N/A | Lower CPU and memory usage | [OK] Good |