MonoBehaviour

Struct MonoBehaviour 

Source
pub struct MonoBehaviour {
    pub m_Enabled: u8,
    pub m_GameObject: PPtr,
    pub m_Name: String,
    pub m_Script: PPtr,
}
Expand description

MonoBehaviour is a class of the Unity engine since version 3.4.0. Exert from Unity’s scripting documentation: 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: 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:Start() Update() FixedUpdate() LateUpdate() OnGUI() OnDisable() OnEnable()See Also: The Deactivating GameObjects page in the manual.

Fields§

§m_Enabled: u8

Enabled Behaviours are Updated, disabled Behaviours are not.

§m_GameObject: PPtr

The game object this component is attached to. A component is always attached to a game object. PPtr<GameObject>: (3.4.0 - 2022.3.2f1)

§m_Name: String

The name of the object.

§m_Script: PPtr

PPtr<MonoScript>: (3.4.0 - 2022.3.2f1)

Trait Implementations§

Source§

impl Debug for MonoBehaviour

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for MonoBehaviour

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for MonoBehaviour

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,