Hi,
I’m an experienced programmer, but kind of newbie in the game programming world. I’ve programmed game before but with more “old school” engine like Panda3d.
In all my previous game programming experience, there were only one game loop where you check for the state and call for update method of all the other objets.
Now, I see that each MonoBehaviour object have their own Update function.
So my question is simple, how do most of you use this functionnality.
I will use an example: I have a GameManager that deal with most of the main state. In it, it update a UI text with the datetime in my game. Right now, the “updateTime” function is called from the Update() of my GameManager like I did in all my game before.
But I’m thinking that maybe to embrace the Unity design, I should only instantiate my “TimeManager” in my GameManager and let him have it’s own Update function?
What is the most common way of doing things?
Thanks!
Update is called each frame on every monobehavior that has one. Meaning that you can have your game manager updating the time each frame (which may be overkill unless you need that exact of time), while a bullet is running movement each frame and a player controller polling for input each frame. Each of these courteous of their own Update() methods.
There are many other useful monobehavior methods to go along with Update(), such as Awake(), Start(), OnEnable(), OnTriggerEnter, etc. These are called in a specific order, which is also very important when dependencies are in place. Here is a full list of the available methods, and here is the order in which they are called.
For hobby projects, it is ok to use the default update implementation within Unity. But for serious projects, you should implement the “game loop” pattern or, also called, “manager” pattern.