UnityEngine.MonoBehaviour

From GPhys Developer Community
Revision as of 01:36, 29 April 2026 by Rhosyn Celyn (talk | contribs) (Created page with "= UnityEngine.MonoBehaviour = '''UnityEngine.MonoBehaviour''' is the base class from which every Unity script derives. It allows scripts to be attached to GameObjects and provides core Unity event methods for controlling behavior in the game engine. == Key Features == * Attach scripts to GameObjects in the Unity Editor. * Provides event methods such as <code>Start()</code>, <code>Update()</code>, <code>FixedUpdate()</code>, <code>OnDestroy()</code>, and more. * Suppor...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

UnityEngine.MonoBehaviour

UnityEngine.MonoBehaviour is the base class from which every Unity script derives. It allows scripts to be attached to GameObjects and provides core Unity event methods for controlling behavior in the game engine.

Key Features

  • Attach scripts to GameObjects in the Unity Editor.
  • Provides event methods such as Start(), Update(), FixedUpdate(), OnDestroy(), and more.
  • Supports coroutines for running code over several frames.
  • Enables access to Unity's component system (e.g., GetComponent<T>()).

Commonly Used Methods

Awake()
Called when the script instance is being loaded.
Start()
Called before the first frame update if the script is enabled.
Update()
Called once per frame.
FixedUpdate()
Called at a fixed interval, used for physics updates.
LateUpdate()
Called after all Update functions have been called.
OnEnable()
Called when the object becomes enabled and active.
OnDisable()
Called when the object becomes disabled.
OnDestroy()
Called when the MonoBehaviour will be destroyed.
StartCoroutine(IEnumerator routine)
Starts a coroutine.
StopCoroutine(IEnumerator routine)
Stops a specific coroutine.
StopAllCoroutines()
Stops all coroutines running on this behaviour.
Invoke(string methodName, float time)
Invokes a method after a delay.
CancelInvoke(string methodName)
Cancels all Invoke calls with the given method name.
IsInvoking(string methodName)
Returns true if the method is invoked.

Commonly Used Properties

enabled
Enables/disables the behaviour (bool).
isActiveAndEnabled
Returns true if the behaviour is enabled and the GameObject is active (bool).
gameObject
The GameObject this component is attached to.
transform
The Transform attached to this GameObject.
tag
The tag of this GameObject.
name
The name of this GameObject.
hideFlags
Flags to control object visibility in the editor.


See Also

This page describes the MonoBehaviour base class in Unity.