# Sandbox.GameObject

An object in the scene. Functionality is added using Components. A GameObject has a transform, which explains its position,
rotation and scale, relative to its parent. It also has a name, and can be enabled or disabled. When disabled, the GameObject
is still in the scene, but the components don't tick and are all disabled.

- Kind: class
- Namespace: `Sandbox`
- Assembly: `Sandbox.Engine`

## Constructors

- [`GameObject`](/api/Sandbox.GameObject/.ctor): Create a new GameObject with the given name. Will be created enabled.

## Fields

- [`DiffObjectDefinitions`](/api/Sandbox.GameObject/DiffObjectDefinitions): Defines objects within a scene hierarchy we want to track for prefab diffing and patching.

## Properties

- [`Active`](/api/Sandbox.GameObject/Active): Is this gameobject active. For it to be active, it needs to be enabled, all of its ancestors need to be enabled, and it needs to be in a scene.
- [`Children`](/api/Sandbox.GameObject/Children)
- [`Components`](/api/Sandbox.GameObject/Components): Access components on this GameObject
- [`DebugOverlay`](/api/Sandbox.GameObject/DebugOverlay): Allows drawing of temporary debug shapes and text in the scene
- [`Enabled`](/api/Sandbox.GameObject/Enabled): Is this gameobject enabled?
- [`EnabledToken`](/api/Sandbox.GameObject/EnabledToken): This token is cancelled when the GameObject ceases to exist, or is disabled
- [`Flags`](/api/Sandbox.GameObject/Flags)
- [`HasGimzoHandle`](/api/Sandbox.GameObject/HasGimzoHandle)
- [`HasGizmoHandle`](/api/Sandbox.GameObject/HasGizmoHandle)
- [`Id`](/api/Sandbox.GameObject/Id)
- [`IsDeserializing`](/api/Sandbox.GameObject/IsDeserializing): True if this GameObject is being deserialized right now
- [`IsDestroyed`](/api/Sandbox.GameObject/IsDestroyed): Return true if this object is destroyed. This will also return true if the object is marked to be destroyed soon.
- [`IsNetworkRoot`](/api/Sandbox.GameObject/IsNetworkRoot): If true then this object is the root of a networked object.
- [`IsPrefabInstance`](/api/Sandbox.GameObject/IsPrefabInstance): This GameObject is part of a prefab instance.
- [`IsPrefabInstanceRoot`](/api/Sandbox.GameObject/IsPrefabInstanceRoot): This GameObject is the root of a prefab instance. Returns true for regular instance roots and nested prefab instance roots.
- [`IsProxy`](/api/Sandbox.GameObject/IsProxy): True if this is a networked object and is owned by another client. This means that we're not controlling this object, so shouldn't try to move it or anything.
- [`IsRoot`](/api/Sandbox.GameObject/IsRoot): Returns true of this is a root object. Root objects are parented to the scene.
- [`IsStatic`](/api/Sandbox.GameObject/IsStatic): This object never moves during gameplay, letting rendering, physics and navmesh make static optimizations. Children inherit this via [Sandbox.GameObjectFlags.Static](/api/Sandbox.GameObjectFlags/Static) on any ancestor.
- [`IsValid`](/api/Sandbox.GameObject/IsValid): True if the GameObject is not destroyed
- [`LocalPosition`](/api/Sandbox.GameObject/LocalPosition): The local position of the game object.
- [`LocalRotation`](/api/Sandbox.GameObject/LocalRotation): The local rotation of the game object.
- [`LocalScale`](/api/Sandbox.GameObject/LocalScale): The local scale of the game object.
- [`LocalTransform`](/api/Sandbox.GameObject/LocalTransform): The local transform of the game object.
- [`Name`](/api/Sandbox.GameObject/Name): The GameObject's name is usually used for debugging, and for finding it in the scene.
- [`Network`](/api/Sandbox.GameObject/Network): Access network information for this GameObject.
- [`Networked`](/api/Sandbox.GameObject/Networked): OBSOLETE: Use NetworkMode instead.
- [`NetworkInterpolation`](/api/Sandbox.GameObject/NetworkInterpolation): Whether our networked transform will be interpolated. This property will only be synchronized for a root network object. Obsolete: 09/12/2025
- [`NetworkMode`](/api/Sandbox.GameObject/NetworkMode): How should this object be networked to other clients? By default, a [Sandbox.GameObject](/api/Sandbox.GameObject) will be networked as part of the [Sandbox.GameObject.Scene](/api/Sandbox.GameObject/Scene) snapshot.
- [`Parent`](/api/Sandbox.GameObject/Parent)
- [`PrefabInstanceSource`](/api/Sandbox.GameObject/PrefabInstanceSource)
- [`Root`](/api/Sandbox.GameObject/Root): Return the root GameObject. The root is the object that is parented to the scene - which could very much be this object.
- [`RootNetwork`](/api/Sandbox.GameObject/RootNetwork)
- [`Scene`](/api/Sandbox.GameObject/Scene): The scene that this GameObject is in.
- [`Tags`](/api/Sandbox.GameObject/Tags)
- [`Transform`](/api/Sandbox.GameObject/Transform): Our position relative to our parent, or the scene if we don't have any parent.
- [`WorldPosition`](/api/Sandbox.GameObject/WorldPosition): The world position of the game object.
- [`WorldRotation`](/api/Sandbox.GameObject/WorldRotation): The world rotation of the game object.
- [`WorldScale`](/api/Sandbox.GameObject/WorldScale): The world scale of the game object.
- [`WorldTransform`](/api/Sandbox.GameObject/WorldTransform): The world transform of the game object.

## Methods

- [`AddComponent`](/api/Sandbox.GameObject/AddComponent): Add a component to this GameObject
- [`AddSibling`](/api/Sandbox.GameObject/AddSibling)
- [`BreakFromPrefab`](/api/Sandbox.GameObject/BreakFromPrefab): We are cloned from a prefab. Stop that.
- [`Clear`](/api/Sandbox.GameObject/Clear): Destroy all components and child objects
- [`Clone`](/api/Sandbox.GameObject/Clone): Create a unique copy of the passed in GameObject
- [`Deserialize`](/api/Sandbox.GameObject/Deserialize)
- [`Destroy`](/api/Sandbox.GameObject/Destroy): Destroy this object. Will actually be destroyed at the start of the next frame.
- [`DestroyImmediate`](/api/Sandbox.GameObject/DestroyImmediate): Destroy this object immediately. Calling this might cause some problems if functions are expecting the object to still exist, so it's not always a good idea.
- [`EditLog`](/api/Sandbox.GameObject/EditLog)
- [`GetAllObjects`](/api/Sandbox.GameObject/GetAllObjects)
- [`GetBounds`](/api/Sandbox.GameObject/GetBounds): This is slow, and somewhat innacurate. Don't call it every frame!
- [`GetComponent`](/api/Sandbox.GameObject/GetComponent): Get a component on this GameObject
- [`GetComponentInChildren`](/api/Sandbox.GameObject/GetComponentInChildren): Get component on this GameObject or on descendant GameObjects
- [`GetComponentInParent`](/api/Sandbox.GameObject/GetComponentInParent): Get component on this GameObject and on ancestor GameObjects
- [`GetComponents`](/api/Sandbox.GameObject/GetComponents): Get components on this GameObject
- [`GetComponentsInChildren`](/api/Sandbox.GameObject/GetComponentsInChildren): Get components on this GameObject and on descendant GameObjects
- [`GetComponentsInParent`](/api/Sandbox.GameObject/GetComponentsInParent): Get components on this GameObject and on ancestor GameObjects
- [`GetLocalBounds`](/api/Sandbox.GameObject/GetLocalBounds): This is slow, and somewhat innacurate. Don't call it every frame!
- [`GetNextSibling`](/api/Sandbox.GameObject/GetNextSibling): Get the GameObject after us,
- [`GetOrAddComponent`](/api/Sandbox.GameObject/GetOrAddComponent): Add a component to this GameObject
- [`GetPrefab`](/api/Sandbox.GameObject/GetPrefab): Get the GameObject of a prefab from file path
- [`IsAncestor`](/api/Sandbox.GameObject/IsAncestor): Returns true if the passed in object is an ancestor
- [`IsDeletable`](/api/Sandbox.SceneExtensions/IsDeletable)
- [`IsDescendant`](/api/Sandbox.GameObject/IsDescendant): Returns true if the passed in object is a decendant of ours
- [`JsonRead`](/api/Sandbox.GameObject/JsonRead)
- [`JsonWrite`](/api/Sandbox.GameObject/JsonWrite)
- [`MakeNameUnique`](/api/Sandbox.GameObject/MakeNameUnique)
- [`NetworkSpawn`](/api/Sandbox.GameObject/NetworkSpawn): Spawn on the network. If you have permission to spawn entities, this will spawn on everyone else's clients, and you will be the owner.
- [`PasteComponent`](/api/Sandbox.SceneExtensions/PasteComponent): Paste a [Sandbox.Component](/api/Sandbox.Component) as a new component on the target [Sandbox.GameObject](/api/Sandbox.GameObject).
- [`PlaySound`](/api/Sandbox.GameObject/PlaySound): Play this sound on this GameObject. The sound will follow the position of the GameObject. You'll be able to use GameObject.StopAllSounds to stop all sounds that are following this GameObject.
- [`RunEvent`](/api/Sandbox.GameObject/RunEvent)
- [`Serialize`](/api/Sandbox.GameObject/Serialize): Returns either a full JsonObject with all the GameObjects data, or if this GameObject is a prefab instance, it will return an object containing the patch/diff between instance and prefab.
- [`SetParent`](/api/Sandbox.GameObject/SetParent)
- [`SetPrefabSource`](/api/Sandbox.GameObject/SetPrefabSource)
- [`ShouldShowInHierarchy`](/api/Sandbox.SceneExtensions/ShouldShowInHierarchy): Return true if this object should be shown in the GameObject list
- [`StopAllSounds`](/api/Sandbox.GameObject/StopAllSounds): Stop any sounds playing on this GameObject
- [`UpdateFromPrefab`](/api/Sandbox.GameObject/UpdateFromPrefab)
