Using Update() to keep UI correct

Wouldn’t it be better to update the UI on the event of change? eg. enemy death for score and hits on player to update health? instead of always checking on the Update() even if its all the same most of the time?

Better is subjective. Better for someone learning the absolute basics of game programming, probably not.

It would be more efficient.

For quick prototypes and simple games it probably doesn’t matter if the UI is constantly polling to get its data. But using events or actions to only update the UI when something changes is definitely better to optimize for a production level build.

One thing to be wary of is that if anything in a UI canvas changes, it invalidates that canvas’s hierarchy and has to rebuild/redraw it. Apparently this can get pretty expensive. So one common suggestion is to separate each UI into its own canvas.

Here’s a GDC talk which goes into more detail about optimization specifically with canvases: https://youtu.be/_wxitgdx-UI?t=1454

1 Like

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

Privacy & Terms