# Object

> Base class for all objects Unity can reference.

## Definition

* **Type:** Class
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public class Object
```

## Remarks

`UnityEngine.Object` is the base class for all built-in Unity objects. Don't derive from or instantiate this class directly. Instead, use the appropriate subclass such as [GameObject](/engine/6000.0/script-reference/unityengine/gameobject.md), [MonoBehaviour](/engine/6000.0/script-reference/unityengine/monobehaviour.md), or [ScriptableObject](/engine/6000.0/script-reference/unityengine/scriptableobject.md).

Any public variable you make that derives from `UnityEngine.Object` is shown in the Inspector as a drop target, allowing you to set the value from the GUI.

Some APIs are designed to work with any Unity Object, so Object appears as a type in their signatures. For example, [Resources.LoadAll](/engine/6000.0/script-reference/unityengine/resources/loadall.md), [EditorJsonUtility.ToJson](/engine/6000.0/script-reference/unityeditor/editorjsonutility/tojson.md) and [SerializedObject](/engine/6000.0/script-reference/unityeditor/serializedobject.md).

Each instance of a class that derives from `UnityEngine.Object` 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.

Detached objects retain their InstanceID, but the object can't be used to call methods or access properties. Comparing objects in this state with `null` evaluates `true`, 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 `Object.ReferenceEquals(myobject, null)` returns `false`.

The [null-conditional operator](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#null-conditional-operator) (`?.`) and the [null-coalescing operator](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#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](/engine/6000.0/manual/scripting/object-oriented-development/fundamental-unity-types/class-object.md).

## Properties

| Property                                                                     | Description                                                                            |
| ---------------------------------------------------------------------------- | -------------------------------------------------------------------------------------- |
| [hideFlags](/engine/6000.0/script-reference/unityengine/object/hideflags.md) | Controls whether the object is hidden, saved with the scene, and editable by the user. |
| [name](/engine/6000.0/script-reference/unityengine/object/name.md)           | The name of the object.                                                                |

## Methods

| Method                                                                               | Description                           |
| ------------------------------------------------------------------------------------ | ------------------------------------- |
| [GetHashCode](/engine/6000.0/script-reference/unityengine/object/gethashcode.md)     | Returns the hash code for the object. |
| [GetInstanceID](/engine/6000.0/script-reference/unityengine/object/getinstanceid.md) | Gets the instance ID of the object.   |
| [ToString](/engine/6000.0/script-reference/unityengine/object/tostring.md)           | Returns the name of the object.       |

## Static Methods

| Method                                                                                               | Description                                                                                                                                                                               |
| ---------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [Destroy](/engine/6000.0/script-reference/unityengine/object/destroy.md)                             | Removes a GameObject, component, or asset.                                                                                                                                                |
| [DestroyImmediate](/engine/6000.0/script-reference/unityengine/object/destroyimmediate.md)           | Destroys the specified object immediately. Use with caution and in Edit mode only.                                                                                                        |
| [DontDestroyOnLoad](/engine/6000.0/script-reference/unityengine/object/dontdestroyonload.md)         | Do not destroy the target [Object](/engine/6000.0/script-reference/unityengine/object.md) when loading a new [Scene](/engine/6000.0/script-reference/unityeditor/searchservice/scene.md). |
| [FindAnyObjectByType](/engine/6000.0/script-reference/unityengine/object/findanyobjectbytype.md)     | Retrieves any active loaded object of the specified type.                                                                                                                                 |
| [FindFirstObjectByType](/engine/6000.0/script-reference/unityengine/object/findfirstobjectbytype.md) | Retrieves the first active loaded object of Type `type`.                                                                                                                                  |
| [FindObjectsByType](/engine/6000.0/script-reference/unityengine/object/findobjectsbytype.md)         | Retrieves a list of all loaded objects of Type `type` and sorts the results according to `sortMode`.                                                                                      |
| [Instantiate](/engine/6000.0/script-reference/unityengine/object/instantiate.md)                     | Clones the object `original` and returns the clone.                                                                                                                                       |
| [InstantiateAsync](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)           | 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 ==](/engine/6000.0/script-reference/unityengine/object/op-equality.md)   | Compares two object references to see if they refer to the same object. |
| [bool](/engine/6000.0/script-reference/unityengine/object/op-implicit.md)          | Determines whether the object exists.                                   |
| [operator !=](/engine/6000.0/script-reference/unityengine/object/op-inequality.md) | Compares if two objects refer to a different object.                    |
