Object
Base class for all objects Unity can reference.
Read time 2 minutesLast updated 2 days ago
Definition
- Type: Class
- Namespace: UnityEngine
- Assembly: UnityEngine.CoreModule
public class Object
Remarks
UnityEngine.ObjectAny public variable you make that derives from is shown in the Inspector as a drop target, allowing you to set the value from the GUI.
UnityEngine.ObjectSome APIs are designed to work with any Unity Object, so Object appears as a type in their signatures. For example, Resources.LoadAll, EditorJsonUtility.ToJson and SerializedObject.
Each instance of a class that derives from is linked to a counterpart native object. If the native counterpart is destroyed before the managed object is garbage collected, or if the instance references a missing asset or missing type, the managed instance can be in a detached state.
UnityEngine.ObjectDetached objects retain their InstanceID, but the object can't be used to call methods or access properties. Comparing objects in this state with evaluates , because of Unity's custom implementation of the equality () and inequality () operators and bool. However, because the managed object is not truly null, a call to returns .
nulltrue==!=Object.ReferenceEquals(myobject, null)falseThe null-conditional operator () and the null-coalescing operator() are not supported with Unity Objects because they can't be overridden to treat detached objects the same as null. It's only safe to use those operators if the checked objects are guaranteed to never be in a detached state.
?.??Additional Resources: Object in the Unity manual.
Properties
Property | Description |
|---|---|
| hideFlags | Controls whether the object is hidden, saved with the scene, and editable by the user. |
| name | The name of the object. |
Methods
Method | Description |
|---|---|
| GetHashCode | Returns the hash code for the object. |
| 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 specified object immediately. Use with caution and in Edit mode only. |
| DontDestroyOnLoad | Do not destroy the target Object when loading a new Scene. |
| FindAnyObjectByType | Retrieves any active loaded object of the specified type. |
| FindFirstObjectByType | Retrieves the first active loaded object of Type |
| FindObjectsByType | Retrieves a list of all loaded objects of Type |
| Instantiate | Clones the object |
| InstantiateAsync | Captures a snapshot of the original object that's related to another GameObject and obtains an AsyncInstantiateOperation instance of the resulting objects. |
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |