MonoBehaviour is a base class that many Unity scripts derive from.
MonoBehaviour offers life cycle functions that make it easier to develop with Unity.
This class doesn't support the null-conditional operator (?.) and the null-coalescing operator (??).
For code samples, see the individual MonoBehaviour methods.
Note: There is a checkbox for enabling or disabling MonoBehaviour in the Unity Editor. It disables functions when unticked. If none of these functions are present in the script, the Unity Editor does not display the checkbox. The functions are:
See Also: The Deactivating GameObjects page in the manual.
|Allow a specific instance of a MonoBehaviour to run in edit mode (only available in the editor).
|Disabling this lets you skip the GUI layout phase.
|Cancels all Invoke calls on this MonoBehaviour.
|Invokes the method methodName in time seconds.
|Invokes the method methodName in time seconds, then repeatedly every repeatRate seconds.
|Is any invoke on methodName pending?
|Starts a Coroutine.
|Stops all coroutines running on this behaviour.
|Stops the first coroutine named methodName, or the coroutine stored in routine running on this behaviour.
|Logs message to the Unity Console (identical to Debug.Log).
|Awake is called when an enabled script instance is being loaded.
|Frame-rate independent MonoBehaviour.FixedUpdate message for physics calculations.
|LateUpdate is called every frame, if the Behaviour is enabled.
|Callback for setting up animation IK (inverse kinematics).
|Callback for processing animation movements for modifying root motion.
|Sent to all GameObjects when the player gets or loses focus.
|Sent to all GameObjects when the application pauses.
|Sent to all GameObjects before the application quits.
|If OnAudioFilterRead is implemented, Unity will insert a custom filter into the audio DSP chain.
|OnBecameInvisible is called when the renderer is no longer visible by any camera.
|OnBecameVisible is called when the renderer became visible by any camera.
|OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.
|Sent when an incoming collider makes contact with this object's collider (2D physics only).
|OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.
|Sent when a collider on another object stops touching this object's collider (2D physics only).
|OnCollisionStay is called once per frame for every Collider or Rigidbody that touches another Collider or Rigidbody.
|Sent each frame where a collider on another object is touching this object's collider (2D physics only).
|Called on the client when you have successfully connected to a server.
|OnControllerColliderHit is called when the controller hits a collider while performing a Move.
|Destroying the attached Behaviour will result in the game or Scene receiving OnDestroy.
|This function is called when the behaviour becomes disabled.
|Called on the client when the connection was lost or you disconnected from the server.
|Implement OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn.
|Implement OnDrawGizmosSelected to draw a gizmo if the object is selected.
|This function is called when the object becomes enabled and active.
|Called on the client when a connection attempt fails for some reason.
|Called on clients or servers when there is a problem connecting to the MasterServer.
|OnGUI is called for rendering and handling GUI events.
|Called when a joint attached to the same game object broke.
|Called when a Joint2D attached to the same game object breaks.
|Called on clients or servers when reporting events from the MasterServer.
|OnMouseDown is called when the user has pressed the mouse button while over the Collider.
|OnMouseDrag is called when the user has clicked on a Collider and is still holding down the mouse.
|Called when the mouse enters the Collider.
|Called when the mouse is not any longer over the Collider.
|Called every frame while the mouse is over the Collider.
|OnMouseUp is called when the user has released the mouse button.
|OnMouseUpAsButton is only called when the mouse is released over the same Collider as it was pressed.
|Called on objects which have been network instantiated with Network.Instantiate.
|OnParticleCollision is called when a particle hits a Collider.
|OnParticleSystemStopped is called when all particles in the system have died, and no new particles will be born. New particles cease to be created either after Stop is called, or when the duration property of a non-looping system has been exceeded.
|OnParticleTrigger is called when any particles in a Particle System meet the conditions in the trigger module.
|OnParticleUpdateJobScheduled is called when a Particle System's built-in update job has been scheduled.
|Called on the server whenever a new player has successfully connected.
|Called on the server whenever a player disconnected from the server.
|Event function that Unity calls after a Camera renders the scene.
|Event function that Unity calls before a Camera culls the scene.
|Event function that Unity calls before a Camera renders the scene.
|Event function that Unity calls after a Camera has finished rendering, that allows you to modify the Camera's final image.
|OnRenderObject is called after camera has rendered the Scene.
|Used to customize synchronization of variables in a script watched by a network view.
|Called on the server whenever a Network.InitializeServer was invoked and has completed.
|This function is called when the list of children of the transform of the GameObject has changed.
|This function is called when a direct or indirect parent of the transform of the GameObject has changed.
|When a GameObject collides with another GameObject, Unity calls OnTriggerEnter.
|Sent when another object enters a trigger collider attached to this object (2D physics only).
|OnTriggerExit is called when the Collider other has stopped touching the trigger.
|Sent when another object leaves a trigger collider attached to this object (2D physics only).
|OnTriggerStay is called once per physics update for every Collider other that is touching the trigger.
|Sent each frame where another object is within a trigger collider attached to this object (2D physics only).
|Editor-only function that Unity calls when the script is loaded or a value changes in the Inspector.
|OnWillRenderObject is called for each camera if the object is visible and not a UI element.
|Reset to default values.
|Start is called on the frame when a script is enabled just before any of the Update methods are called the first time.
|Update is called every frame, if the MonoBehaviour is enabled.
|Enabled Behaviours are Updated, disabled Behaviours are not.
|Reports whether a GameObject and its associated Behaviour is active and enabled.
|The game object this component is attached to. A component is always attached to a game object.
|The tag of this game object.
|The Transform attached to this GameObject.
|Should the object be hidden, saved with the Scene or modifiable by the user?
|The name of the object.
|Calls the method named methodName on every MonoBehaviour in this game object or any of its children.
|Checks the GameObject's tag against the defined tag.
|Returns the component of type if the GameObject has one attached.
|Returns the Component of type in the GameObject or any of its children using depth first search.
|Returns the Component of type in the GameObject or any of its parents.
|Returns all components of Type type in the GameObject.
|Returns all components of Type type in the GameObject or any of its children. Works recursively.
|Returns all components of Type type in the GameObject or any of its parents.
|Calls the method named methodName on every MonoBehaviour in this game object.
|Calls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour.
|Gets the component of the specified type, if it exists.
|Gets the instance ID of the object.
|Returns the name of the object.
|Removes a GameObject, component or asset.
|Destroys the object obj immediately. You are strongly recommended to use Destroy instead.
|Do not destroy the target Object when loading a new Scene.
|Returns the first active loaded object of Type type.
|Gets a list of all loaded objects of Type type.
|Clones the object original and returns the clone.