Why even Intermediate courses don't use UnityEvents or Observer Pattern

Am curious to know why even the Intermediate 2D RPG course would not use Events or Observer Pattern to update the Score UI ? Is it not favoured for performance reasons or for some other reason (debugging) ?

For example

public class PlayerHealth: Singleton<PlayerHealth>{
      public event Action<int> PlayerHealthChangedEvent;
      ...
      
      public void HealPlayer() {
            if (_currentHealth < maxHealth) {
                _currentHealth += 1;
                HealthChangedEvent?.Invoke(_currentHealth);
            }
        }
}

public class UpdateUI:Monobehaviour{
     ...
     private void Start(){
          PlayerHealth.Instance.HealthChangedEvent += UpdateHealth;
     }
     private void UpdateHealth(int currentHealth){
         healthSlider.value = currentHealth;  
    }
}

Are there any Unity Project based courses that teach the Observer design pattern or Events ?

The Programming Design Patterns course talks about the Observer Pattern. Events are also used quite a bit in the Turn Based Strategy course

Thanks.
Unity Turn based strategy looks super scooper.

1 Like

We also teach the Observer pattern in the RPG Course series (Core Combat, Inventory, Dialogues and Quests, and Shops And Abilities, though oddly enough, Sam never does change the Hud to use the Observer pattern. It’s left for the students to go back and apply it to the Hud.

Privacy & Terms