Performance: Why UI communicates game state
This concept affects how quickly the game UI updates to reflect changes, impacting interaction responsiveness and visual stability.
Jump into concepts and practice - no test required
void OnScoreChanged(int newScore) { scoreText.text = newScore.ToString(); } void OnHealthChanged(float newHealth) { healthBar.value = newHealth; } // Subscribe to game state events and update UI only when values change
void Update() {
scoreText.text = gameState.score.ToString();
healthBar.value = gameState.health;
// Updates every frame regardless of changes
}| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Update UI every frame | High (many updates) | Many reflows triggered | High paint cost | [X] Bad |
| Update UI on state change | Minimal updates | Single or few reflows | Low paint cost | [OK] Good |
int health = 50;
Text healthText;
void UpdateHealthUI() {
healthText.text = "Health: " + health;
}
UpdateHealthUI();
What will be shown on the UI if health is 50?int score = 10;
Text scoreText;
void UpdateScore() {
scoreText.text = score;
}