A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://docs.unity3d.com/Manual/../ScriptReference/../Manual/../ScriptReference/MonoBehaviour.html below:

Unity - Scripting API: MonoBehaviour

MonoBehaviour

class in UnityEngine

/

Inherits from:Behaviour

/

Implemented in:UnityEngine.CoreModule

Suggest a change Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close Submission failed

For some reason your suggested change could not be submitted. Please <a>try again</a> in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close Your name Your email Suggestion*

Cancel

Switch to Manual Description

MonoBehaviour is a base class that many Unity scripts derive from.

MonoBehaviour offers life cycle functions that make it easier to develop with Unity.

MonoBehaviours always exist as a Component of a GameObject, and can be instantiated with GameObject.AddComponent. Objects that need to exist independently of a GameObject should derive from ScriptableObject instead.

A MonoBehaviour can be deleted with Object.Destroy or Object.DestroyImmediate. When the parent GameObject is destroyed all components are automatically deleted, including MonoBehaviours.

After the underlying component is destroyed, the C# object for the MonoBehaviour remains in memory until garbage is collected. A MonoBehaviour in this state acts as if it is null. For example, it returns true for a "obj == null" check. However, this class doesn't support the null-conditional operator (?.) and the null-coalescing operator (??).

When a MonoBehaviour is serialized, the value of C# fields are included according to Unity's Serialization rules. See Script Serialization for details. The serialized data also includes internal properties, such as the reference to the MonoScript that tracks the implementation class for the object.

For code samples, see the individual MonoBehaviour methods.

Note: In the Editor, when the MonoBehaviour component is deactivated through the checkbox in the Inspector, it stops receiving calls to its Event functions.

Additional resources: The Deactivating GameObjects page in the manual.

Properties Property Description destroyCancellationToken Cancellation token raised when the MonoBehaviour is destroyed (Read Only). didAwake Returns a boolean value which represents if Awake was called. didStart Returns a boolean value which represents if Start was called. runInEditMode Allow a specific instance of a MonoBehaviour to run in edit mode (only available in the editor). useGUILayout Disabling this lets you skip the GUI layout phase. Public Methods Method Description CancelInvoke Cancels all Invoke calls on this MonoBehaviour. Invoke Invokes the method methodName in time seconds. InvokeRepeating Invokes the method methodName in time seconds, then repeatedly every repeatRate seconds. IsInvoking Is any invoke on methodName pending? StartCoroutine Starts a Coroutine. StopAllCoroutines Stops all coroutines running on this behaviour. StopCoroutine Stops the first coroutine named methodName, or the coroutine stored in routine running on this behaviour. Static Methods Method Description print Logs a message to the Unity Console. Functionally equivalent to Debug.Log. Messages Message Description Awake Unity calls Awake when an enabled script instance is being loaded. FixedUpdate Frame-rate independent MonoBehaviour.FixedUpdate message for physics calculations. LateUpdate LateUpdate is called every frame, if the Behaviour is enabled. OnAnimatorIK Callback for setting up animation IK (inverse kinematics). OnAnimatorMove Callback for processing animation movements for modifying root motion. OnApplicationFocus Sent to all GameObjects when the player gets or loses focus. OnApplicationPause Sent to all GameObjects when the playing application pauses or resumes on losing or regaining focus. OnApplicationQuit Sent to all GameObjects before the application quits. OnAudioFilterRead If OnAudioFilterRead is implemented, Unity will insert a custom filter into the audio DSP chain. OnBecameInvisible OnBecameInvisible is called when the renderer is no longer visible by any camera. OnBecameVisible OnBecameVisible is called when the renderer became visible by any camera. OnCollisionEnter OnCollisionEnter is called when this collider/rigidbody has begun touching another rigidbody/collider. OnCollisionEnter2D Sent when an incoming collider makes contact with this object's collider (2D physics only). OnCollisionExit OnCollisionExit is called when this collider/rigidbody has stopped touching another rigidbody/collider. OnCollisionExit2D Sent when a collider on another object stops touching this object's collider (2D physics only). OnCollisionStay OnCollisionStay is called once per frame for every Collider or Rigidbody that touches another Collider or Rigidbody. OnCollisionStay2D Sent each frame where a collider on another object is touching this object's collider (2D physics only). OnConnectedToServer Called on the client when you have successfully connected to a server. OnControllerColliderHit OnControllerColliderHit is called when the controller hits a collider while performing a Move. OnDestroy Destroying the attached Behaviour will result in the game or Scene receiving OnDestroy. OnDisable This function is called when the behaviour becomes disabled. OnDrawGizmos Implement OnDrawGizmos if you want to draw gizmos that are also pickable and always drawn. OnDrawGizmosSelected Implement OnDrawGizmosSelected to draw a gizmo if the object is selected. OnEnable This function is called when the object becomes enabled and active. OnFailedToConnect Called on the client when a connection attempt fails for some reason. OnGUI OnGUI is called for rendering and handling GUI events. OnJointBreak Called when a joint attached to the same game object broke. OnJointBreak2D Called when a Joint2D attached to the same game object breaks. OnMouseDown OnMouseDown is called when the user presses the left mouse button while over the Collider. OnMouseDrag OnMouseDrag is called when the user has clicked on a Collider and is still holding down the mouse. OnMouseEnter Called when the mouse enters the Collider. OnMouseExit Called when the mouse is not any longer over the Collider. OnMouseOver Called every frame while the mouse is over the 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 Collider as it was pressed. OnParticleCollision OnParticleCollision is called when a particle hits a Collider. OnParticleSystemStopped 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 OnParticleTrigger is called when any particles in a Particle System meet the conditions in the trigger module. OnParticleUpdateJobScheduled OnParticleUpdateJobScheduled is called when a Particle System's built-in update job has been scheduled. OnPostRender Event function that Unity calls after a Camera renders the scene. OnPreCull Event function that Unity calls before a Camera culls the scene. OnPreRender Event function that Unity calls before a Camera renders the scene. OnRenderImage Event function that Unity calls after a Camera has finished rendering, that allows you to modify the Camera's final image. OnRenderObject OnRenderObject is called after camera has rendered the Scene. OnServerInitialized Called on the server whenever a Network.InitializeServer was invoked and has completed. OnTransformChildrenChanged This function is called when the list of children of the transform of the GameObject has changed. OnTransformParentChanged This function is called when a direct or indirect parent of the transform of the GameObject has changed. OnTriggerEnter When a GameObject collides with another GameObject, Unity calls OnTriggerEnter. OnTriggerEnter2D Sent when another object enters a trigger collider attached to this object (2D physics only). OnTriggerExit OnTriggerExit is called when the Collider other has stopped touching the trigger. OnTriggerExit2D Sent when another object leaves a trigger collider attached to this object (2D physics only). OnTriggerStay OnTriggerStay is called once per physics update for every Collider other that is touching the trigger. OnTriggerStay2D Sent once per physics update when another object is within a trigger collider attached to this object (2D physics only). OnValidate Editor-only function that Unity calls when the script is loaded or a value changes in the Inspector. OnWillRenderObject OnWillRenderObject is called for each camera if the object is visible and not a UI element. Reset Reset to default values. Start Start is called on the frame when a script is enabled just before any of the Update methods are called the first time. Update Update is called every frame, if the MonoBehaviour is enabled. Inherited Members Properties Property Description enabled Enabled Behaviours are Updated, disabled Behaviours are not. isActiveAndEnabled Reports whether a GameObject and its associated Behaviour is active and enabled. 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. transform The Transform attached to this GameObject. hideFlags Should the object be hidden, saved with the Scene or modifiable by the user? name The name of the object. Public Methods Method Description BroadcastMessage Calls the method named methodName on every MonoBehaviour in this game object or any of its children. CompareTag Checks the GameObject's tag against the defined tag. GetComponent Gets a reference to a component of type T on the same GameObject as the component specified. GetComponentInChildren Gets a reference to a component of type T on the same GameObject as the component specified, or any child of the GameObject. GetComponentIndex Gets the index of the component on its parent GameObject. GetComponentInParent Gets a reference to a component of type T on the same GameObject as the component specified, or any parent of the GameObject. GetComponents Gets references to all components of type T on the same GameObject as the component specified. GetComponentsInChildren Gets references to all components of type T on the same GameObject as the component specified, and any child of the GameObject. GetComponentsInParent Gets references to all components of type T on the same GameObject as the component specified, and any parent of the GameObject. SendMessage Calls the method named methodName on every MonoBehaviour in this game object. SendMessageUpwards Calls the method named methodName on every MonoBehaviour in this game object and on every ancestor of the behaviour. TryGetComponent Gets the component of the specified type, if it exists. GetInstanceID Gets the instance ID of the object. ToString Returns the name of the object. Static Methods Method Description Destroy Removes a GameObject, component or asset. DestroyImmediate Destroys the object obj immediately. You are strongly recommended to use Destroy instead. DontDestroyOnLoad Do not destroy the target Object when loading a new Scene. FindAnyObjectByType Retrieves any active loaded object of Type type. FindFirstObjectByType Retrieves the first active loaded object of Type type. FindObjectsByType Retrieves a list of all loaded objects of Type type. Instantiate Clones the object original and returns the clone. InstantiateAsync Captures a snapshot of the original object (that must be related to some GameObject) and returns the AsyncInstantiateOperation. Operators Operator Description bool Does the object exist? operator != Compares if two objects refer to a different object. operator == Compares two object references to see if they refer to the same object.

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4