Updated Event Execution Order

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(New page: ==Game loop== ===Instantiation=== For objects that were instantiated '''last''' game iteration: *'''Start''' ===Physics loop=== Physics is run in a loop until timestep*count > Time.d...)
 
m (Fixed some typos, added more info about coroutines)
Line 1: Line 1:
 
 
 
==Game loop==
 
==Game loop==
  
  
===Instantiation===
+
===After an instantiation===
For objects that were instantiated '''last''' game iteration:
+
For objects that were instantiated '''last''' game loop iteration:
 
*'''Start'''
 
*'''Start'''
  
Line 15: Line 13:
 
*'''OnCollisionEnter'''/'''OnCollisionStay'''/'''OnCollisionExit'''
 
*'''OnCollisionEnter'''/'''OnCollisionStay'''/'''OnCollisionExit'''
 
*'''OnTriggerEnter'''/'''OnTriggerStay'''/'''OnTriggerExit'''
 
*'''OnTriggerEnter'''/'''OnTriggerStay'''/'''OnTriggerExit'''
*'''WaitForFixedUpdate''' (In a coroutine)
 
  
  
 +
===Update events===
 
The rest of the events are run once per game loop iteration:
 
The rest of the events are run once per game loop iteration:
 +
*'''WaitForFixedUpdate''' ''(Coroutines which yielded WaitForFixedUpdate will resume execution as soon as the physics loop finishes)''
 +
 +
 
*'''Update'''
 
*'''Update'''
*'''WaitForSeconds'''/'''yield'''/'''yield return 0''' (In a coroutine)
+
*'''WaitForSeconds'''/'''yield'''/'''yield return 0''' ''(Coroutines which yielded one of these will resume execution here, with WaitForSeconds resuming after the defined time)''
 
*'''LateUpdate'''
 
*'''LateUpdate'''
  
Line 31: Line 32:
 
*'''OnRenderObject'''
 
*'''OnRenderObject'''
 
*'''OnPostRender'''
 
*'''OnPostRender'''
*'''OnRenderImage''' (pro only)
+
*'''OnRenderImage''' ''(pro only)''
  
  
Line 39: Line 40:
  
 
===Before the frame ends===
 
===Before the frame ends===
*'''WaitForEndOfFrame''' (In a coroutine)
+
*'''WaitForEndOfFrame''' ''(Coroutines which yielded WaitForEndOfFrame will resume execution before the game loop finishes)''
  
  
Line 49: Line 50:
 
Repeated once per object:
 
Repeated once per object:
 
*'''Awake'''
 
*'''Awake'''
*'''OnEnable''' (if the object is active)
+
*'''OnEnable''' ''(if the object is active)''
  
  
Line 70: Line 71:
 
Repeated once per scene object:
 
Repeated once per scene object:
 
*'''Awake'''
 
*'''Awake'''
*'''OnEnable''' (if the object is active)
+
*'''OnEnable''' ''(if the object is active)''
  
  
Line 96: Line 97:
 
*'''Awake''' - called during MonoBehaviour instantiation
 
*'''Awake''' - called during MonoBehaviour instantiation
 
*'''OnEnable'''/'''OnDisable''' - OnEnable called during MonoBehaviour instantiation
 
*'''OnEnable'''/'''OnDisable''' - OnEnable called during MonoBehaviour instantiation
*'''Reset''' (Editor Only)
+
*'''Reset''' - called when the script is reset ''(Editor Only)''

Revision as of 01:59, 9 June 2009

Contents

Game loop

After an instantiation

For objects that were instantiated last game loop iteration:

  • Start


Physics loop

Physics is run in a loop until timestep*count > Time.deltaTime:

  • FixedUpdate
  • Physics simulation
  • OnCollisionEnter/OnCollisionStay/OnCollisionExit
  • OnTriggerEnter/OnTriggerStay/OnTriggerExit


Update events

The rest of the events are run once per game loop iteration:

  • WaitForFixedUpdate (Coroutines which yielded WaitForFixedUpdate will resume execution as soon as the physics loop finishes)


  • Update
  • WaitForSeconds/yield/yield return 0 (Coroutines which yielded one of these will resume execution here, with WaitForSeconds resuming after the defined time)
  • LateUpdate


Rendering

  • OnPreCull
  • OnBecameVisible/OnBecameInvisible
  • OnWillRenderObject
  • OnPreRender
  • OnRenderObject
  • OnPostRender
  • OnRenderImage (pro only)


  • OnGUI
  • OnDrawGizmos (Only when scene is drawn, even if object is inactive)


Before the frame ends

  • WaitForEndOfFrame (Coroutines which yielded WaitForEndOfFrame will resume execution before the game loop finishes)



First scene load

Repeated once per object:

  • Awake
  • OnEnable (if the object is active)


At the beginning of the next frame, per object:

  • Start



After calling Application.LoadLevel

Before the level loads

Repeated once per active object, after the end of the current frame:

  • OnDisable


Level loads

After level loads

Repeated once per scene object:

  • Awake
  • OnEnable (if the object is active)


Repeated once per active DontDestroyOnLoad object from last level:

  • OnEnable


Repeated once per active object:

  • OnLevelWasLoaded



When quitting

For all active objects:

  • OnApplicationQuit
  • OnDisable



Immediate events

These are all called immediately when certain functions are called (e.g. Instantiate, setting enabled):

  • Awake - called during MonoBehaviour instantiation
  • OnEnable/OnDisable - OnEnable called during MonoBehaviour instantiation
  • Reset - called when the script is reset (Editor Only)
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox