Event Execution Order

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
m (Finished adding links)
(Update events)
Line 26: Line 26:
 
*'''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseDown.html OnMouseDown]''' / '''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseUp.html OnMouseUp]''' / '''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseDrag.html OnMouseDrag]''' / '''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseEnter.html OnMouseEnter]''' / '''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseExit.html OnMouseExit]''' / '''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseOver.html OnMouseOver]'''
 
*'''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseDown.html OnMouseDown]''' / '''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseUp.html OnMouseUp]''' / '''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseDrag.html OnMouseDrag]''' / '''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseEnter.html OnMouseEnter]''' / '''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseExit.html OnMouseExit]''' / '''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.OnMouseOver.html OnMouseOver]'''
 
*'''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Update.html Update]'''
 
*'''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.Update.html Update]'''
*'''[http://unity3d.com/support/documentation/ScriptReference/WaitForSeconds.html WaitForSeconds]''' / '''[http://unity3d.com/support/documentation/ScriptReference/YieldInstruction.html yield]''' / '''yield return 0''' ''(Coroutines which yielded one of these will resume execution here, with WaitForSeconds resuming after the defined time)''
+
*'''[http://unity3d.com/support/documentation/ScriptReference/WaitForSeconds.html WaitForSeconds]''' / '''[http://unity3d.com/support/documentation/ScriptReference/YieldInstruction.html yield]''' / '''yield return null''' ''(Coroutines which yielded one of these will resume execution here, with WaitForSeconds resuming after the defined time)''
 
*'''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.LateUpdate.html LateUpdate]'''
 
*'''[http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.LateUpdate.html LateUpdate]'''
  

Revision as of 20:06, 13 July 2011

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:


Physics loop

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


Update events

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

Rendering


  • 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:


At the beginning of the next frame, per object:



After calling Application.LoadLevel

Before the level loads

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


Level loads

After level loads

Repeated once per scene object:


Repeated once per active DontDestroyOnLoad object from last level:


Repeated once per active object:



When quitting

For all active objects:



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