Api Sandbox GameObject
class

GameObject

public class 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.

Constructors

GameObject(String name)

Create a new GameObject with the given name. Will be created enabled.

GameObject(Boolean enabled, String name)

Create a new GameObject with the given enabled state and name.

GameObject(GameObject parent, Boolean enabled, String name)

Create a new GameObject with the given parent, enabled state and name.

GameObject(Boolean enabled)
GameObject()

Properties

Name Type Description
Scene Scene The scene that this GameObject is in.
Transform GameTransform Our position relative to our parent, or the scene if we don't have any parent.
Name String The GameObject's name is usually used for debugging, and for finding it in the scene.
IsRoot Boolean Returns true of this is a root object. Root objects are parented to the scene.
Root GameObject Return the root GameObject. The root is the object that is parented to the scene - which could very much be this object.
EnabledToken CancellationToken This token is cancelled when the GameObject ceases to exist, or is disabled
Components virtual ComponentList Access components on this GameObject
Enabled Boolean Is this gameobject enabled?
Parent GameObject
Children List<GameObject>
Active Boolean 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.
DebugOverlay DebugOverlaySystem Allows drawing of temporary debug shapes and text in the scene
IsValid virtual Boolean True if the GameObject is not destroyed
IsDestroyed Boolean Return true if this object is destroyed. This will also return true if the object is marked to be destroyed soon.
Flags GameObjectFlags
IsDeserializing Boolean True if this GameObject is being deserialized right now
HasGimzoHandle Boolean
HasGizmoHandle Boolean
Id Guid
LocalTransform Transform The local transform of the game object.
LocalPosition Vector3 The local position of the game object.
LocalRotation Rotation The local rotation of the game object.
LocalScale Vector3 The local scale of the game object.
IsProxy Boolean 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.
IsNetworkRoot Boolean If true then this object is the root of a networked object.
Networked Boolean OBSOLETE: Use NetworkMode instead.
NetworkMode NetworkMode How should this object be networked to other clients? By default, a GameObject will be networked as part of the Scene snapshot.
NetworkInterpolation Boolean Whether our networked transform will be interpolated. This property will only be synchronized for a root network object. Obsolete: 09/12/2025
Network NetworkAccessor Access network information for this GameObject.
RootNetwork NetworkAccessor
PrefabInstanceSource String
IsPrefabInstance Boolean This GameObject is part of a prefab instance.
IsPrefabInstanceRoot Boolean This GameObject is the root of a prefab instance. Returns true for regular instance roots and nested prefab instance roots.
Tags GameTags
WorldTransform Transform The world transform of the game object.
WorldPosition Vector3 The world position of the game object.
WorldRotation Rotation The world rotation of the game object.
WorldScale Vector3 The world scale of the game object.

Methods

GameObject Clone(CloneConfig cloneConfig)

Create a unique copy of the passed in GameObject

static GameObject Clone(String prefabPath, CloneConfig? config = null)
static GameObject Clone(String prefabPath, Transform transform, GameObject parent = null, Boolean startEnabled = True, String name = null)

Clone a prefab from path

static GameObject Clone(PrefabFile prefabFile, CloneConfig? config = null)
static GameObject Clone(PrefabFile prefabFile, Transform transform, GameObject parent = null, Boolean startEnabled = True, String name = null)

Clone a prefab from path

GameObject Clone(Transform transform, GameObject parent = null, Boolean startEnabled = True, String name = null)

Create a unique copy of the GameObject

GameObject Clone()

Create a unique copy of the GameObject

GameObject Clone(Vector3 position)

Create a unique copy of the GameObject

GameObject Clone(Vector3 position, Rotation rotation)

Create a unique copy of the GameObject

GameObject Clone(Vector3 position, Rotation rotation, Vector3 scale)

Create a unique copy of the GameObject

GameObject Clone(GameObject parent, Vector3 position, Rotation rotation, Vector3 scale)

Create a unique copy of the GameObject

Boolean IsDescendant(GameObject decendant)

Returns true if the passed in object is a decendant of ours

Boolean IsAncestor(GameObject ancestor)

Returns true if the passed in object is an ancestor

Void AddSibling(GameObject go, Boolean before, Boolean keepWorldPosition = True)
Void SetParent(GameObject value, Boolean keepWorldPosition = True)
Void MakeNameUnique()
IEnumerable<GameObject> GetAllObjects(Boolean enabled)
virtual Void EditLog(String name, Object source)
BBox GetBounds()

This is slow, and somewhat innacurate. Don't call it every frame!

BBox GetLocalBounds()

This is slow, and somewhat innacurate. Don't call it every frame!

GameObject GetNextSibling(Boolean enabledOnly)

Get the GameObject after us,

virtual Void Destroy()

Destroy this object. Will actually be destroyed at the start of the next frame.

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

Void Clear()

Destroy all components and child objects

virtual Void RunEvent(Action<T> action, FindMode find = 69)
T AddComponent(Boolean startEnabled = True)

Add a component to this GameObject

T GetOrAddComponent(Boolean startEnabled = True)

Add a component to this GameObject

T GetComponent(Boolean includeDisabled = False)

Get a component on this GameObject

IEnumerable<T> GetComponents(Boolean includeDisabled = False)

Get components on this GameObject

IEnumerable<T> GetComponentsInChildren(Boolean includeDisabled = False, Boolean includeSelf = True)

Get components on this GameObject and on descendant GameObjects

T GetComponentInChildren(Boolean includeDisabled = False, Boolean includeSelf = True)

Get component on this GameObject or on descendant GameObjects

IEnumerable<T> GetComponentsInParent(Boolean includeDisabled = False, Boolean includeSelf = True)

Get components on this GameObject and on ancestor GameObjects

T GetComponentInParent(Boolean includeDisabled = False, Boolean includeSelf = True)

Get component on this GameObject and on ancestor GameObjects

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

Boolean NetworkSpawn(NetworkSpawnOptions options)

Spawn on the network with the specified options. If you have permission to spawn entities, this will spawn on everyone else's clients.

Boolean NetworkSpawn(Boolean enabled, Connection owner)

Spawn on the network. If you have permission to spawn entities, this will spawn on everyone else's clients and the owner will be the connection provided.

Boolean NetworkSpawn(Connection owner)

Spawn on the network. If you have permission to spawn entities, this will spawn on everyone else's clients and the owner will be the connection provided.

Void BreakFromPrefab()

We are cloned from a prefab. Stop that.

Void UpdateFromPrefab()
static GameObject GetPrefab(String prefabFilePath)

Get the GameObject of a prefab from file path

Void SetPrefabSource(String prefabSource)
virtual JsonObject Serialize(SerializeOptions options = null)

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.

virtual Void Deserialize(JsonObject node)
virtual Void Deserialize(JsonObject node, DeserializeOptions options)
static override Object JsonRead(Utf8JsonReader reader, Type targetType)
static override Void JsonWrite(Object value, Utf8JsonWriter writer)
SoundHandle PlaySound(SoundEvent sound, Vector3 positionOffset = null)

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.

Void StopAllSounds(Single fadeOutTime = 0)

Stop any sounds playing on this GameObject

Fields

Name Type Description
DiffObjectDefinitions static HashSet<TrackedObjectDefinition> Defines objects within a scene hierarchy we want to track for prefab diffing and patching.
Assembly: Sandbox.Engine Namespace: Sandbox Full Name: Sandbox.GameObject