How Unity call it's MonoBehaviour Method or Events like Update

 Ever wonder how the magic events of unity Behavior work:

void Awake()

{

}

void Start()

{

} 

void Update()

{

}

// Or other unity magic events like OnEnable, OnDisable, Late Update, Fixed Update, etc.,

The simple answer comes into mind that maybe unity use reflections to find Mono Behaviour methods in order to call it every time or maybe they use override to those methods but actually, this is not happening. So, how unity it calls its event, especially the Update event that calls on every frame.?

Steps to call Unity Magic Events:

The way Messaging system or magic events are works in unity3dis:

1.      Unity scripting runtime Mono or IL2CPP access MonoBehaviour derived (type) script.

2.      Look for magic events and cache them.

3.      Like if a MonoBehaviour derived script has an update event then, the script will be added into a list (list of scripts) that will be updated on every frame.

4.      Now during gameplay, unity iterates over the list and Trigger the Unity events. This is the reason that if you make your event public or private they don’t get affected.

 Hope that this post will clarify how smartly unity calls its built-in events.

Read More: Coding Forums for Developers

Post a Comment

0 Comments