Rationale for using events vs Update()

I was also wondering why we’re not using events similar to this Q. Is there a reason why we don't use events?

But I think one possible reason here is that this is a real time vs turn based game. IOW, things are constantly changing vs changing at very discrete increments so we can get a lot more mileage out of Update() here. For example distances between enemies and players, cooldown timers for next attack change in real time and it makes sense to check things every frame. I also remember we want to implement cursor affordances at some point and so again checking every frame makes sense.

I’m curious if that’s part of the rationale or if I’m overthinking it.

For the most part, it’s just early in the course to introduce the observer pattern.
In some things, however, like the PlayerController and AIController, it doesn’t make as much sense to make things event driven. UI, on the other hand, should almost always be event driven.

I’m assuming here you mean things like the on the screen buttons, menus, etc. And not Input for Mouse Button or Key presses?

UI? Everything. If you’re using Buttons, the EventSystem will tell the button it’s been pressed. The button then executes the linked method. Event driven. Updating values in the UI like your health or stats? Event driven. We do it in Update here, but it should be changed to observer pattern once you’re comfortable with it.

Wow interesting. Even in the turn based strategy course where we used the observer pattern extensively, we still used Update() for processing user input for player control.

Looking at this figure then this would have the effect of acting on all user input after Physics but before Update(). ? Did I read this right?

Sorry, I was in the mindset of UI on the screen, buttons and the such. Both the Third Person course and this course poll for current input every frame, either in the Update(0 or Tick() depending on the course. Sorry for that.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms