Performance: MonoBehaviour lifecycle
MEDIUM IMPACT
This affects the frame rendering speed and responsiveness of Unity games by controlling when and how often scripts run during the game loop.
void Start() {
// Precompute data once
precomputedData = ComputeHeavyData();
}
void Update() {
// Use precomputed data without allocations
UseData(precomputedData);
}void Update() {
// Heavy calculations or frequent allocations here
for (int i = 0; i < 1000; i++) {
var temp = new Vector3(i, i, i);
}
}| Pattern | CPU Usage | Frame Drops | Garbage Collection | Verdict |
|---|---|---|---|---|
| Heavy work in Update | High CPU every frame | Frequent frame drops | High GC pressure | [X] Bad |
| Precompute in Start, light Update | Low CPU per frame | Smooth frames | Minimal GC | [OK] Good |