MonoBehaviour Manual     Reference     Scripting  
Scripting > Runtime Classes > MonoBehaviour
MonoBehaviour Inherits from Behaviour

MonoBehaviour is the base class every script derives from.

Using Javascript every script automatically derives from MonoBehaviour. When using C# or Boo you have to explicitly derive from MonoBehaviour.

Note: The checkbox for disabling a MonoBehavior (on the editor) will only prevent Start(), Awake(), Update(), FixedUpdate(), and OnGUI() from executing. If none of these functions are present, the checkbox is not displayed.

See Also: The chapter on scripting in the manual.

Variables
useGUILayout

Disabling this lets you skip the GUI layout phase.

Functions
Invoke

Invokes the method methodName in time seconds.

InvokeRepeating

Invokes the method methodName in time seconds.

CancelInvoke

Cancels all Invoke calls on this MonoBehaviour.

IsInvoking

Is any invoke on methodName pending?

StartCoroutine

Starts a coroutine.

StopCoroutine

Stops all coroutines named methodName running on this behaviour.

StopAllCoroutines

Stops all coroutines running on this behaviour.

Overridable Functions
Update

Update is called every frame, if the MonoBehaviour is enabled.

LateUpdate

LateUpdate is called every frame, if the Behaviour is enabled.

FixedUpdate

This function is called every fixed framerate frame, if the MonoBehaviour is enabled.

Awake

Awake is called when the script instance is being loaded.

Start

Start is called just before any of the Update methods is called the first time.

Reset

Reset to default values.

OnMouseEnter

OnMouseEnter is called when the mouse entered the GUIElement or Collider.

OnMouseOver

OnMouseOver is called every frame while the mouse is over the GUIElement or Collider.

OnMouseExit

OnMouseExit is called when the mouse is not any longer over the GUIElement or Collider.

OnMouseDown

OnMouseDown is called when the user has pressed the mouse button while over the GUIElement or Collider.

OnMouseUp

OnMouseUp is called when the user has released the mouse button.

OnMouseUpAsButton

OnMouseUpAsButton is only called when the mouse is released over the same GUIElement or Collider as it was pressed.

OnMouseDrag

OnMouseDrag is called when the user has clicked on a GUIElement or Collider and is still holding down the mouse.

OnTriggerEnter

OnTriggerEnter is called when the Collider other enters the trigger.

OnTriggerExit

OnTriggerExit is called when the Collider other has stopped touching the trigger.

OnTriggerStay

OnTriggerStay is called once per frame for every Collider other that is touching the trigger.

OnCollisionEnter

OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider.

OnCollisionExit

OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider.

OnCollisionStay

OnCollisionStay is called once per frame for every collider/rigidbody that is touching rigidbody/collider.

OnControllerColliderHit

OnControllerColliderHit is called when the controller hits a collider while performing a Move.

OnJointBreak

Called when a joint attached to the same game object broke.

OnParticleCollision

OnParticleCollision is called when a particle hits a collider.

OnBecameVisible

OnBecameVisible is called when the renderer became visible by any camera.

OnBecameInvisible

OnBecameInvisible is called when the renderer is no longer visible by any camera.

OnLevelWasLoaded

This function is called after a new level was loaded.

OnEnable

This function is called when the object becomes enabled and active.

OnDisable

This function is called when the behaviour becomes disabled () or inactive.

OnDestroy

This function is called when the MonoBehaviour will be destroyed.

OnPreCull

OnPreCull is called before a camera culls the scene.

OnPreRender

OnPreRender is called before a camera starts rendering the scene.

OnPostRender

OnPostRender is called after a camera finished rendering the scene.

OnRenderObject

OnRenderObject is called after camera has rendered the scene.

OnWillRenderObject

OnWillRenderObject is called once for each camera if the object is visible.

OnGUI

OnGUI is called for rendering and handling GUI events.

OnRenderImage

OnRenderImage is called after all rendering is complete to render image

OnDrawGizmosSelected

Implement this OnDrawGizmosSelected if you want to draw gizmos only if the object is selected.

OnDrawGizmos

Implement this OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn.

OnApplicationPause

Sent to all game objects when the player pauses.

OnApplicationFocus

Sent to all game objects when the player gets or looses focus.

OnApplicationQuit

Sent to all game objects before the application is quit.

OnPlayerConnected

Called on the server whenever a new player has successfully connected.

OnServerInitialized

Called on the server whenever a Network.InitializeServer was invoked and has completed.

OnConnectedToServer

Called on the client when you have successfully connected to a server

OnPlayerDisconnected

Called on the server whenever a player disconnected from the server.

OnDisconnectedFromServer

Called on the client when the connection was lost or you disconnected from the server.

OnFailedToConnect

Called on the client when a connection attempt fails for some reason.

OnFailedToConnectToMasterServer

Called on clients or servers when there is a problem connecting to the MasterServer.

OnMasterServerEvent

Called on clients or servers when reporting events from the MasterServer.

OnNetworkInstantiate

Called on objects which have been network instantiated with Network.Instantiate

OnSerializeNetworkView

Used to customize synchronization of variables in a script watched by a network view.

OnAudioFilterRead

If OnAudioFilterRead is implemented, Unity will insert a custom filter into the audio DSP chain.

Class Functions
print

Logs message to the Unity Console. This function is identical to Debug.Log.

Inherited members
Inherited Variables
enabled

Enabled Behaviours are Updated, disabled Behaviours are not.

transform

The Transform attached to this GameObject (null if there is none attached).

rigidbody

The Rigidbody attached to this GameObject (null if there is none attached).

camera

The Camera attached to this GameObject (null if there is none attached).

light

The Light attached to this GameObject (null if there is none attached).

animation

The Animation attached to this GameObject (null if there is none attached).

constantForce

The ConstantForce attached to this GameObject (null if there is none attached).

renderer

The Renderer attached to this GameObject (null if there is none attached).

audio

The AudioSource attached to this GameObject (null if there is none attached).

guiText

The GUIText attached to this GameObject (null if there is none attached).

networkView

The NetworkView attached to this GameObject (Read Only). (null if there is none attached)

guiTexture

The GUITexture attached to this GameObject (Read Only). (null if there is none attached)

collider

The Collider attached to this GameObject (null if there is none attached).

hingeJoint

The HingeJoint attached to this GameObject (null if there is none attached).

particleEmitter

The ParticleEmitter attached to this GameObject (null if there is none attached).

particleSystem

The ParticleSystem attached to this GameObject (null if there is none attached).

gameObject

The game object this component is attached to. A component is always attached to a game object.

tag

The tag of this game object.

name

The name of the object.

hideFlags

Should the object be hidden, saved with the scene or modifiable by the user?

Inherited Functions
GetComponent

Returns the component of Type type if the game object has one attached, null if it doesn't.

GetComponentInChildren

Returns the component of Type type in the GameObject or any of its children using depth first search.

GetComponentsInChildren

Returns all components of Type type in the GameObject or any of its children.

GetComponents

Returns all components of Type type in the GameObject.

CompareTag

Is this game object tagged tag?

SendMessageUpwards

Calls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour

SendMessage

Calls the method named methodName on every MonoBehaviour in this game object.

BroadcastMessage

Calls the method named methodName on every MonoBehaviour in this game object or any of its children.

GetInstanceID

Returns the instance id of the object.

ToString

Returns the name of the game object.

Inherited Class Functions
operator bool

Does the object exist?

Instantiate

Clones the object original and returns the clone.

Destroy

Removes a gameobject, component or asset.

DestroyImmediate

Destroys the object obj immediately. It is strongly recommended to use Destroy instead.

FindObjectsOfType

Returns a list of all active loaded objects of Type type.

FindObjectOfType

Returns the first active loaded object of Type type.

operator ==

Compares if two objects refer to the same

operator !=

Compares if two objects refer to a different object

DontDestroyOnLoad

Makes the object target not be destroyed automatically when loading a new scene.