Unity3D MonoBehaviour Lifecycle

Unity3D 2013. 1. 3. 12:06
반응형

Unity3D MonoBehaviour Lifecycle

When you’re working with Unity3D, there are many different hooks you can hang your code on, and it’s often helpful to know which hooks are going to be called at what times.

I did some experimentation to figure out exactly when a bunch of the most important things happen, and put the information together into this handy infographic, which people appear to find useful:

My experiments were done under Unity 3.4, but as far as I know nothing has changed for 3.5 or 4.x.

The only bit of info I’d add that I’ve discovered since is that Awake doesn’t get called until the GameObject that the MonoBehaviour is attached to becomes active. One almost always creates a MonoBehaviour on an active GameObject, causing Awake to be called immediately (i.e. during the Instantiate call), but be aware of it if you’re doing something unusual (like adding components to Prefabs, which are permanently inactive).

If there’s other lifecycle questions that this infographic doesn’t answer clearly enough, post them in the comments and I’ll see about getting them added in sometime.

반응형
: