Updating the Action Points text

Hi there, firstly thank you for putting together this course. I am fairly new to coding and new to mostly anything with Unity (I have completed the 2D unity course), I have been setting my own little challenges while following along to see if I can figure things out before you show them and when updating the text for the action points I tried to do this again.
In my own version I created an Update() method in the UnitActionSystemUI script and ran UpdateActionPoints() from there which seemed to work in the expected way, I see that you didn’t do this and so assume that this way is probably not good I’m just curious as to what problems would be likely from having Update() in there or why an event is preferred ?

Simply put, performance.

An event fires when something changes… so if the Action points change, then we call an event and UpdateActionPoints(). Update fires every frame. This means that the Action Points text is “changed” many times per second, and that adds to the amount of code that has to run every frame, and by extension lowers the frame rate.

3 Likes

Yup you can just Update it every single frame, the only downside is like Brian said that it’s pretty wasteful, you are running that code every single frame even when nothing changes.
It’s not necessarily a problem, updating a simple text object is pretty fast, but following the pattern of “only update things when things change” is a good thing to do in general.

4 Likes

Privacy & Terms