Updated Event Execution Order

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Removing all content from page)
m (Reverted edits by Joseph05408 (Talk); changed back to last version by Mike)
Line 1: Line 1:
 +
Author: [[User:Mike|Michael Garforth]]
  
 +
 +
 +
=='''Game loop'''==
 +
The following all happens in a single loop, in the order specified
 +
Physics does not necessarily run each time, and can run multiple times
 +
 +
 +
===After an instantiation===
 +
For objects that were instantiated '''last''' game loop iteration:
 +
*'''Start'''
 +
 +
 +
===Physics loop===
 +
Physics is run in a loop, iterating over the following until physics has caught up to the current frame:
 +
*'''FixedUpdate'''
 +
*Physics simulation
 +
*'''OnCollisionEnter'''/'''OnCollisionStay'''/'''OnCollisionExit'''
 +
*'''OnTriggerEnter'''/'''OnTriggerStay'''/'''OnTriggerExit'''
 +
*'''WaitForFixedUpdate''' ''(Coroutines which yielded WaitForFixedUpdate will resume execution after the next physics iteration completes)''
 +
 +
 +
===Update events===
 +
The rest of the events are run once per game loop iteration:
 +
*'''OnMouseDown'''/'''OnMouseUp'''/'''OnMouseDrag'''/'''OnMouseEnter'''/'''OnMouseExit'''/'''OnMouseOver'''
 +
*'''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''' ''(Called multiple times. Layout then Repaint events are called first, followed by a Layout and keyboard/mouse event for each input event)''
 +
*'''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 next 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)''

Revision as of 18:59, 19 October 2009

Author: Michael Garforth


Contents

Game loop

The following all happens in a single loop, in the order specified Physics does not necessarily run each time, and can run multiple times


After an instantiation

For objects that were instantiated last game loop iteration:

  • Start


Physics loop

Physics is run in a loop, iterating over the following until physics has caught up to the current frame:

  • FixedUpdate
  • Physics simulation
  • OnCollisionEnter/OnCollisionStay/OnCollisionExit
  • OnTriggerEnter/OnTriggerStay/OnTriggerExit
  • WaitForFixedUpdate (Coroutines which yielded WaitForFixedUpdate will resume execution after the next physics iteration completes)


Update events

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

  • OnMouseDown/OnMouseUp/OnMouseDrag/OnMouseEnter/OnMouseExit/OnMouseOver
  • 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 (Called multiple times. Layout then Repaint events are called first, followed by a Layout and keyboard/mouse event for each input event)
  • 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 next 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