Performance: DontDestroyOnLoad usage
MEDIUM IMPACT
This affects how game objects persist across scene loads, impacting memory usage and scene load performance.
void Awake() {
if (FindObjectsOfType<GameManager>().Length > 1) {
Destroy(this.gameObject);
return;
}
DontDestroyOnLoad(this.gameObject);
}void Awake() {
DontDestroyOnLoad(this.gameObject);
}
// No check for duplicates, so multiple instances accumulate after scene reloads| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| DontDestroyOnLoad without duplicate check | N/A | N/A | N/A | [X] Bad |
| DontDestroyOnLoad with duplicate check | N/A | N/A | N/A | [OK] Good |