Object
The 'Object' class serves as the foundational layer for all elements in Unity scenes. Whether building intricate environments with GameObjects, infusing functionality through Components, or enhancing realism with Unity's pre-built assets such as textures and meshes, everything stems from the root 'Object' class.
Moreover, the 'Object' class provides an interactive gateway to Unity's lifecycle events. This includes initialization of objects upon creation, updates occurring in tandem with the game's frame rate, and the clean-up processes when objects are destroyed. This understanding of the object lifecycle is pivotal in managing memory usage, performance optimisation, and orchestrating smooth gameplay sequences.
To grasp the full extent of how the 'Object' class shapes the world of Unity, head over to the official Unity documentation for detailed insights.
Properties
The name property represents the name of the Object. This could be the name you gave an asset in Unity, or the default name of a created GameObject, like 'GameObject1'. Find out more.
Methods
Immediately destroys the specified Object. You are strongly recommended to use Destroy instead. This function should only be used when writing editor code because it completely bypasses Unity's normal life-cycle events. More details here.
Parameters
obj
ObjectThe Object to destroy.
Returns
Does not return anything.
Destroys the specified Object after all frame updates have finished processing. Learn more.
Parameters
obj
ObjectThe Object to destroy.
Returns
Does not return anything.
The 'Instantiate' method clones the object original and returns the clone. This can be immensely useful in various gameplay mechanics like respawning, shooting projectiles, etc. Learn more about Instantiate here.
The 'GetInstanceID' method provides a unique identifer for the object instance. More details about Instance IDs can be found here.
Returns
The unique identifier for the object instance.
Makes the object target not be destroyed automatically when loading a new scene, which is the default behavior. Learn more here.
Parameters
target
ObjectThe Object that should not be destroyed.
Returns
This method does not return a value.
This method returns the first active loaded object of the given type. It is a generic method with return type of the generic parameter. It returns null if no GameObject is active in the hierarchy. More details can be obtained here.
This method returns the first object to match the specified type, including inactive objects. It is slower than FindObjectByType, as it searches all objects in the scene, not just the active ones. Learn more here.
The 'FindAnyObjectByType' method finds all objects in the scene of the specified type, including active and inactive ones. As the method must search every single object in the scene, this operation can be performance-intensive. Details here.