Like other fundamental parts such as GameObject, Compoent, Time, Input and Physics, Monobehaviour is an essential member for writing the script, which is the soul of an GameObject. This article is the introduction of the Monobehaviour.
When we use MonoBehaviour, we need to pay attention to the following methods:
Awake: Awake is called only once when a script instance is loaded. We mostly complete the initialization of member variables in this class.
Update: When MonoBehaviour is enabled, its Update is called every frame. The number of runs depends on the hardware performance. Usually better hardware will run more with Update functions.
FixedUpdate: When MonoBehaviour is enabled, its FixedUpdate is called every fixed frame.
OnEnable: This function is called when the object becomes available or activated. For example, it will be called when
OnDisable: This function is called when the object becomes unavailable or inactive. Similar to OnEnable.
OnDestroy: This function is called when MonoBehaviour will be destroyed.
Here is an image on the life cycle methods:
Join the newsletter to receive the latest updates in your inbox.