Using Update() vs detecting when to update and performing a single function call
Sorry if this question is a bit general, but I'm new to Unity and I'm trying to learn about certain Unity conventions. Namely, I'm curious about usage of the Update() function.
From a traditional software development perspective, calling a function over and over again the entire time a program is running is something that we would try to avoid mainly for performance reasons. I understand that Unity is optimized for the Update() function, but how far are we willing to go to avoid it?
Let's say I have some UI elements that I want to keep up to date with the state of the game, and the things the user does in the game should update values in the UI. There are a couple of ways that I can think of accomplishing this, and I'm wondering which one is preferable.
Approach 1: Try to detect any situation that should update UI elements, and when we do, call a function that updates the relevant part of the UI. The "detect" part is where this is the most general, and depending on how that's done, it could probably change the answer to my question. However, lets assume that I'm able to trigger the UI update with efficiency on par with something like a button's OnClick listener.
Approach 2: Use the Update() function to continuously check backend values and update the UI elements when something needs to be updated. I imagine this is easier and simpler to implement, but how much more costly is it in terms of performance?
Thanks in advance.
Your answer
![](https://koobas.hobune.stream/wayback/20220612234127im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple updates or an update for multiple objects? (Performance-wise) 1 Answer
Multiple small update calls vs one large update call? 1 Answer
Update to Unity 2021 Beta = huge performance hit 0 Answers
should I use Invoke or Update? 0 Answers
why did my framerate down from 60 to 40 with uprading to 5.2? 0 Answers