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.

Category: Technology | Tags: One comment »

  • http://twitter.com/robotduck Ben Pitt

    Excellent diagram! Although a tiny discrepency (as I just tweeted to you :) The diagram currently implies that FixedUpdate is called at least once every update cycle. However it is possible for FixedUpdate to not be called at all during an Update, if the game FPS is running faster than the physics timestep. FixedUpdate is run one-or-more times only if the physics simulation has fallen behind the current frame time by one or more physics timesteps. If the game is running at 100fps, and the physics timestep is set to 0.04, you’ll only get a FixedUpdate call on average every four Updates

Back to top