Uninomicon

Documenting the dark corners of the Unity Engine.

User Tools

Site Tools


monobehaviour

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
monobehaviour [2021/04/30 13:35]
177.45.132.86
monobehaviour [2022/01/28 17:26] (current)
73.217.35.3
Line 4: Line 4:
  
 ==== Reset() ==== ==== Reset() ====
-  * This function is only called in editor mode+  * Reset is only called in editor mode.
-  * Reset is called when adding the component for the first time on a GameObject. +
-  * Also, it is called when the user hits the Reset button in the Inspector's context menu.+
   * Very useful to setup values for your attributes, i.e. find a child component.   * Very useful to setup values for your attributes, i.e. find a child component.
   * Use it with the RequireComponent attribute to always get a reference for your component.    * Use it with the RequireComponent attribute to always get a reference for your component. 
Line 17: Line 15:
   * If no FixedUpdate() or Update() events are defined, Start will be run at the end of the frame the object awoke on.    * If no FixedUpdate() or Update() events are defined, Start will be run at the end of the frame the object awoke on. 
  
 +==== OnDisable/OnDestroy() ==== 
 +
 +
 +  * Both events are not affected by script execution order.
 +  * Scene is traversed from each root separately in unspecified (non-hierarchy) order, e.g. [root 1 and all its children], [root 2 and all its children]. "root" being a top-level GameObject in scene.
 +  * All OnDisable calls are performed before all OnDestroy calls within a single root.
 +  * Only root GameObject ''activeSelf'' is changed, for children it will not be changed.
 +  * Components are traversed in the order they appear in Inspector, top to bottom.
 +  * **OnDisable**:
 +    * Call order: same as hierarchy, child before parent. :!:
 +    * ''activeInHierarchy'' propagation can be unfinished for the following siblings and their children.
 +  * **OnDestroy**:
 +    * Call order: same as hierarchy, parent before child. :!:
 +
 +(Above Tested with 2017.4 and an opened Scene running in play mode in editor by stopping the play mode, may differ for other versions/situations)
 +
 +==== OnBecameVisible() ====
 +  * Does not get called if the game object is rendered by a ugui CanvasRenderer
 +
 +==== OnBecameInvisible() ====
 +  * Does not get called if the game object is rendered by a ugui CanvasRenderer
monobehaviour.1619789750.txt.gz · Last modified: 2021/04/30 13:35 by 177.45.132.86