# GameObject

> Base class for all objects that can exist in a scene. Add components to a GameObject to control its appearance and behavior.

## Definition

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

```csharp
public sealed class GameObject : Object
```

## Remarks

The `GameObject` is the fundamental object type in Unity. Use `GameObject` to represent everything in your project, including characters, props, and scenery. A `GameObject` acts as a container for functional [components](/engine/6000.0/script-reference/unityengine/component.md) that determine how the GameObject looks and behaves.

Any script that derives from [MonoBehaviour](/engine/6000.0/script-reference/unityengine/monobehaviour.md) can be added to a `GameObject` as a component. Use the [Component.gameObject](/engine/6000.0/script-reference/unityengine/component/gameobject.md) property from your `MonoBehaviour` code to access the `GameObject` the component is attached to.

`MonoBehaviour` [event functions](/engine/6000.0/manual/scripting/object-oriented-development/managing-update-order/event-functions.md) such as the regular per-frame `MonoBehaviour.Update` allow you to make the object responsive to events. To receive these event callbacks the `GameObject` must be active in the scene, which means both the `activeSelf` and `activeInHierarchy` properties must be `true`.

You can create an empty `GameObject` from code by invoking one of the [constructors](/engine/6000.0/script-reference/unityengine/gameobject/ctor.md). However, a more common method is to instantiate a `GameObject` in [Prefab](/engine/6000.0/manual/working-with-gameobjects/prefabs.md) form, with preconfigured components, property values, and child objects. For more information, refer to [Instantiating Prefabs at runtime](/engine/6000.0/manual/working-with-gameobjects/prefabs/instantiating.md) in the Manual.

You can modify many of the properties of this class in the Editor using the Inspector window. For a more comprehensive guide to using the GameObject class, refer to [GameObject](/engine/6000.0/manual/working-with-gameobjects/gameobject-fundamentals/class-game-object.md) in the Manual.

The following example creates a `GameObject` named "myExampleGO" and adds a component of type [AudioSource](/engine/6000.0/script-reference/unityengine/audiosource.md):

```csharp
using UnityEngine;

public class Example_GameObject : MonoBehaviour
{
    private void Start()
    {
        GameObject myExampleGO = new GameObject("myExampleGO", typeof(AudioSource));
    }
}
```

Additional Resources: [Component](/engine/6000.0/script-reference/unityengine/component.md).

## Constructors

| Constructor                                                                                                                           | Description                                                                                           |
| ------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------- |
| [GameObject()](/engine/6000.0/script-reference/unityengine/gameobject/ctor.md#gameobject\(\))                                         | Creates a new GameObject, with optional parameters to specify a name and set of components to attach. |
| [GameObject(System.String)](/engine/6000.0/script-reference/unityengine/gameobject/ctor.md#gameobject\(string\))                      | Creates a new GameObject, with optional parameters to specify a name and set of components to attach. |
| [GameObject(System.String,System.Type\[\])](/engine/6000.0/script-reference/unityengine/gameobject/ctor.md#gameobject\(string-type\)) | Creates a new GameObject, with optional parameters to specify a name and set of components to attach. |

## Properties

| Property                                                                                         | Description                                                                                               |
| ------------------------------------------------------------------------------------------------ | --------------------------------------------------------------------------------------------------------- |
| [activeInHierarchy](/engine/6000.0/script-reference/unityengine/gameobject/activeinhierarchy.md) | The active state of the GameObject in the Scene hierarchy. True if active, false if inactive. (Read Only) |
| [activeSelf](/engine/6000.0/script-reference/unityengine/gameobject/activeself.md)               | The local active state of the GameObject. True if active, false if inactive. (Read Only)                  |
| [isStatic](/engine/6000.0/script-reference/unityengine/gameobject/isstatic.md)                   | Whether there are any Static Editor Flags set for the GameObject.                                         |
| [layer](/engine/6000.0/script-reference/unityengine/gameobject/layer.md)                         | Integer identifying the layer the GameObject is assigned to.                                              |
| [scene](/engine/6000.0/script-reference/unityengine/gameobject/scene.md)                         | The Scene that contains the GameObject.                                                                   |
| [sceneCullingMask](/engine/6000.0/script-reference/unityengine/gameobject/scenecullingmask.md)   | The Scene culling mask defined for the GameObject. (Read Only)                                            |
| [tag](/engine/6000.0/script-reference/unityengine/gameobject/tag.md)                             | The tag assigned to the GameObject.                                                                       |
| [transform](/engine/6000.0/script-reference/unityengine/gameobject/transform.md)                 | The Transform attached to the GameObject (Read Only).                                                     |

## Methods

| Method                                                                                                       | Description                                                                                                                    |
| ------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------ |
| [AddComponent](/engine/6000.0/script-reference/unityengine/gameobject/addcomponent.md)                       | Adds a component of the specified type to the GameObject.                                                                      |
| [BroadcastMessage](/engine/6000.0/script-reference/unityengine/gameobject/broadcastmessage.md)               | Calls the specified method on every MonoBehaviour attached to the GameObject or any of its children.                           |
| [CompareTag](/engine/6000.0/script-reference/unityengine/gameobject/comparetag.md)                           | Checks if the specified tag is attached to the GameObject.                                                                     |
| [GetComponent](/engine/6000.0/script-reference/unityengine/gameobject/getcomponent.md)                       | Retrieves a reference to a component of the specified type, by providing the name of the component type as a method parameter. |
| [GetComponentAtIndex](/engine/6000.0/script-reference/unityengine/gameobject/getcomponentatindex.md)         | Retrieves a reference to a component at a specified index of the GameObject's array of components.                             |
| [GetComponentCount](/engine/6000.0/script-reference/unityengine/gameobject/getcomponentcount.md)             | Retrieves the total number of components currently attached to the GameObject.                                                 |
| [GetComponentInChildren](/engine/6000.0/script-reference/unityengine/gameobject/getcomponentinchildren.md)   | This is the non-generic version of this method.                                                                                |
| [GetComponentIndex](/engine/6000.0/script-reference/unityengine/gameobject/getcomponentindex.md)             | Retrieves the index of the specified component in the array of components attached to the GameObject.                          |
| [GetComponentInParent](/engine/6000.0/script-reference/unityengine/gameobject/getcomponentinparent.md)       | The non-generic version of this method.                                                                                        |
| [GetComponents](/engine/6000.0/script-reference/unityengine/gameobject/getcomponents.md)                     | The non-generic version of this method.                                                                                        |
| [GetComponentsInChildren](/engine/6000.0/script-reference/unityengine/gameobject/getcomponentsinchildren.md) | The non-generic version of this method.                                                                                        |
| [GetComponentsInParent](/engine/6000.0/script-reference/unityengine/gameobject/getcomponentsinparent.md)     | The non-generic version of this method.                                                                                        |
| [SendMessage](/engine/6000.0/script-reference/unityengine/gameobject/sendmessage.md)                         | Calls the specified method on every MonoBehaviour attached to the GameObject.                                                  |
| [SendMessageUpwards](/engine/6000.0/script-reference/unityengine/gameobject/sendmessageupwards.md)           | Calls the specified method on every MonoBehaviour attached to the GameObject and on every ancestor of the behaviour.           |
| [SetActive](/engine/6000.0/script-reference/unityengine/gameobject/setactive.md)                             | Activates or deactivates the GameObject locally, according to the value of the supplied parameter.                             |
| [TryGetComponent](/engine/6000.0/script-reference/unityengine/gameobject/trygetcomponent.md)                 | The non-generic version of this method.                                                                                        |

## Static Methods

| Method                                                                                                     | Description                                                                                                                                                                                   |
| ---------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [CreatePrimitive](/engine/6000.0/script-reference/unityengine/gameobject/createprimitive.md)               | Creates a GameObject of the specified PrimtiveType with a mesh renderer and appropriate collider.                                                                                             |
| [Find](/engine/6000.0/script-reference/unityengine/gameobject/find.md)                                     | Finds and returns a GameObject with the specified name or hierarchy path.                                                                                                                     |
| [FindGameObjectsWithTag](/engine/6000.0/script-reference/unityengine/gameobject/findgameobjectswithtag.md) | Retrieves an array of all active GameObjects tagged with the specified tag. Returns an empty array if no GameObjects have the tag.                                                            |
| [FindWithTag](/engine/6000.0/script-reference/unityengine/gameobject/findwithtag.md)                       | Retrieves the first active [GameObject](/engine/6000.0/script-reference/unityengine/gameobject.md) tagged with the specified tag. Returns null if no GameObject has the tag.                  |
| [GetScene](/engine/6000.0/script-reference/unityengine/gameobject/getscene.md)                             | Retrieves the Scene which contains the GameObject with the specified instance ID.                                                                                                             |
| [InstantiateGameObjects](/engine/6000.0/script-reference/unityengine/gameobject/instantiategameobjects.md) | Creates a specified number of instances of a GameObject identified by its instance ID and populates NativeArrays with the instance IDs of the new GameObjects and their Transform components. |
| [SetGameObjectsActive](/engine/6000.0/script-reference/unityengine/gameobject/setgameobjectsactive.md)     | Activates or deactivates multiple GameObjects identified by instance ID.                                                                                                                      |

## Inheritance

**Inherited Members:**

* [Object.GetInstanceID()](/engine/6000.0/script-reference/unityengine/object/getinstanceid.md)
* [Object.GetHashCode()](/engine/6000.0/script-reference/unityengine/object/gethashcode.md)
* [Object.InstantiateAsync\<T>(T)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Transform, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, Vector3, Quaternion, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Transform, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, InstantiateParameters, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, InstantiateParameters, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, Vector3, Quaternion, InstantiateParameters, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.InstantiateAsync\<T>(T, int, ReadOnlySpan\<Vector3>, ReadOnlySpan\<Quaternion>, InstantiateParameters, CancellationToken)](/engine/6000.0/script-reference/unityengine/object/instantiateasync.md)
* [Object.Instantiate(Object, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion\))
* [Object.Instantiate(Object, Vector3, Quaternion, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object-vector3-quaternion-transform\))
* [Object.Instantiate(Object)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object\))
* [Object.Instantiate(Object, Scene)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object-scene\))
* [Object.Instantiate\<T>(T, InstantiateParameters)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, InstantiateParameters)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate(Object, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform\))
* [Object.Instantiate(Object, Transform, bool)](/engine/6000.0/script-reference/unityengine/object/instantiate.md#instantiate\(object-transform-bool\))
* [Object.Instantiate\<T>(T)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Vector3, Quaternion, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Instantiate\<T>(T, Transform, bool)](/engine/6000.0/script-reference/unityengine/object/instantiate.md)
* [Object.Destroy(Object, float)](/engine/6000.0/script-reference/unityengine/object/destroy.md)
* [Object.DestroyImmediate(Object, bool)](/engine/6000.0/script-reference/unityengine/object/destroyimmediate.md)
* [Object.FindObjectsByType(Type, FindObjectsSortMode)](/engine/6000.0/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type-findobjectssortmode\))
* [Object.FindObjectsByType(Type, FindObjectsInactive, FindObjectsSortMode)](/engine/6000.0/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytype\(type-findobjectsinactive-findobjectssortmode\))
* [Object.DontDestroyOnLoad(Object)](/engine/6000.0/script-reference/unityengine/object/dontdestroyonload.md)
* [Object.FindObjectsByType\<T>(FindObjectsSortMode)](/engine/6000.0/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(findobjectssortmode\))
* [Object.FindObjectsByType\<T>(FindObjectsInactive, FindObjectsSortMode)](/engine/6000.0/script-reference/unityengine/object/findobjectsbytype.md#findobjectsbytypet\(findobjectsinactive-findobjectssortmode\))
* [Object.FindFirstObjectByType\<T>()](/engine/6000.0/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytypet\(\))
* [Object.FindAnyObjectByType\<T>()](/engine/6000.0/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(\))
* [Object.FindFirstObjectByType\<T>(FindObjectsInactive)](/engine/6000.0/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytypet\(findobjectsinactive\))
* [Object.FindAnyObjectByType\<T>(FindObjectsInactive)](/engine/6000.0/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytypet\(findobjectsinactive\))
* [Object.FindFirstObjectByType(Type)](/engine/6000.0/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytype\(type\))
* [Object.FindAnyObjectByType(Type)](/engine/6000.0/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type\))
* [Object.FindFirstObjectByType(Type, FindObjectsInactive)](/engine/6000.0/script-reference/unityengine/object/findfirstobjectbytype.md#findfirstobjectbytype\(type-findobjectsinactive\))
* [Object.FindAnyObjectByType(Type, FindObjectsInactive)](/engine/6000.0/script-reference/unityengine/object/findanyobjectbytype.md#findanyobjectbytype\(type-findobjectsinactive\))
* [Object.ToString()](/engine/6000.0/script-reference/unityengine/object/tostring.md)
* [Object.name](/engine/6000.0/script-reference/unityengine/object/name.md)
* [Object.hideFlags](/engine/6000.0/script-reference/unityengine/object/hideflags.md)

### 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.                    |
