s&box docs

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

Broader workflow and conceptual references connected to this API.

Constructors

Showing 5 constructors

Methods

Showing 52 methods

protected T __sync_GetValue(Sandbox.WrappedPropertyGet`1<T> p)

protected void __sync_SetValue(Sandbox.WrappedPropertySet`1<T> p)

public T AddComponent(bool startEnabled = True)

Add a component to this GameObject

Parameters

  • startEnabled: Default: True

public void AddSibling(Sandbox.GameObject go, bool before, bool keepWorldPosition = True)

Parameters

  • keepWorldPosition: Default: True

public void BreakFromPrefab()

We are cloned from a prefab. Stop that.

public void Clear()

Destroy all components and child objects

public virtual void Destroy()

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

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

public virtual void EditLog(string name, object source)Obsolete

Obsolete: EditLog is obsolete use Scene.Editor.UndoScope or Scene.Editor.AddUndo instead.

public System.Collections.Generic.IEnumerable`1<Sandbox.GameObject> GetAllObjects(bool enabled)

public BBox GetBounds()

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

public T GetComponent(bool includeDisabled = False)

Get a component on this GameObject

Parameters

  • includeDisabled: Default: False

public T GetComponentInChildren(bool includeDisabled = False, bool includeSelf = True)

Get component on this GameObject or on descendant GameObjects

Parameters

  • includeDisabled: Default: False
  • includeSelf: Default: True

public T GetComponentInParent(bool includeDisabled = False, bool includeSelf = True)

Get component on this GameObject and on ancestor GameObjects

Parameters

  • includeDisabled: Default: False
  • includeSelf: Default: True

public System.Collections.Generic.IEnumerable`1<T> GetComponents(bool includeDisabled = False)

Get components on this GameObject

Parameters

  • includeDisabled: Default: False

public System.Collections.Generic.IEnumerable`1<T> GetComponentsInChildren(bool includeDisabled = False, bool includeSelf = True)

Get components on this GameObject and on descendant GameObjects

Parameters

  • includeDisabled: Default: False
  • includeSelf: Default: True

public System.Collections.Generic.IEnumerable`1<T> GetComponentsInParent(bool includeDisabled = False, bool includeSelf = True)

Get components on this GameObject and on ancestor GameObjects

Parameters

  • includeDisabled: Default: False
  • includeSelf: Default: True

public BBox GetLocalBounds()

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

public Sandbox.GameObject GetNextSibling(bool enabledOnly)

Get the GameObject after us,

public T GetOrAddComponent(bool startEnabled = True)

Add a component to this GameObject

Parameters

  • startEnabled: Default: True

public static Sandbox.GameObject GetPrefab(string prefabFilePath)

Get the GameObject of a prefab from file path

public bool IsAncestor(Sandbox.GameObject ancestor)

Returns true if the passed in object is an ancestor

public bool IsDescendant(Sandbox.GameObject decendant)

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

public static override object JsonRead(System.Text.Json.Utf8JsonReader reader, System.Type targetType)

public static override void JsonWrite(object value, System.Text.Json.Utf8JsonWriter writer)

public void MakeNameUnique()

public Sandbox.SoundHandle PlaySound(Sandbox.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.

Parameters

  • positionOffset: Default: null

public virtual void RunEvent(System.Action`1<T> action, Sandbox.FindMode find = 69)

Parameters

  • find: Default: 69

public virtual System.Text.Json.Nodes.JsonObject Serialize(Sandbox.GameObject.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.

Parameters

  • options: Default: null

public void SetParent(Sandbox.GameObject value, bool keepWorldPosition = True)

Parameters

  • keepWorldPosition: Default: True

public void SetPrefabSource(string prefabSource)Obsolete

Obsolete: Stop using this, you will most likely mess something up.

public void StopAllSounds(float fadeOutTime = 0)

Stop any sounds playing on this GameObject

Parameters

  • fadeOutTime: Default: 0

public void UpdateFromPrefab()

Properties

Showing 38 properties

public bool Sandbox.GameObject.Active { get; set; }

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.

public System.Collections.Generic.List`1<Sandbox.GameObject> Sandbox.GameObject.Children { get; set; }

public virtual sealed Sandbox.ComponentList Sandbox.GameObject.Components { get; set; }

Access components on this GameObject

public Sandbox.DebugOverlaySystem Sandbox.GameObject.DebugOverlay { get; set; }

Allows drawing of temporary debug shapes and text in the scene

public bool Sandbox.GameObject.Enabled { get; set; }

Is this gameobject enabled?

public System.Threading.CancellationToken Sandbox.GameObject.EnabledToken { get; set; }

This token is cancelled when the GameObject ceases to exist, or is disabled

public bool Sandbox.GameObject.HasGimzoHandle { get; set; }Obsolete

Obsolete: Use HasGizmoHandle

public bool Sandbox.GameObject.HasGizmoHandle { get; set; }

public System.Guid Sandbox.GameObject.Id { get; set; }

public bool Sandbox.GameObject.IsDeserializing { get; set; }

True if this GameObject is being deserialized right now

public bool Sandbox.GameObject.IsDestroyed { get; set; }

Return true if this object is destroyed. This will also return true if the object is marked to be destroyed soon.

public bool Sandbox.GameObject.IsNetworkRoot { get; set; }

If true then this object is the root of a networked object.

public bool Sandbox.GameObject.IsPrefabInstance { get; set; }

This GameObject is part of a prefab instance.

public bool Sandbox.GameObject.IsPrefabInstanceRoot { get; set; }

This GameObject is the root of a prefab instance. Returns true for regular instance roots and nested prefab instance roots.

public bool Sandbox.GameObject.IsProxy { get; set; }

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.

public bool Sandbox.GameObject.IsRoot { get; set; }

Returns true of this is a root object. Root objects are parented to the scene.

public virtual bool Sandbox.GameObject.IsValid { get; set; }

True if the GameObject is not destroyed

public Vector3 Sandbox.GameObject.LocalPosition { get; set; }

The local position of the game object.

public Rotation Sandbox.GameObject.LocalRotation { get; set; }

The local rotation of the game object.

public Vector3 Sandbox.GameObject.LocalScale { get; set; }

The local scale of the game object.

public Transform Sandbox.GameObject.LocalTransform { get; set; }

The local transform of the game object.

public string Sandbox.GameObject.Name { get; set; }

The GameObject's name is usually used for debugging, and for finding it in the scene.

public bool Sandbox.GameObject.Networked { get; set; }Obsolete

OBSOLETE: Use NetworkMode instead.

Obsolete: Use GameObject.NetworkMode

public bool Sandbox.GameObject.NetworkInterpolation { get; set; }Obsolete

Whether our networked transform will be interpolated. This property will only be synchronized for a root network object. Obsolete: 09/12/2025

Obsolete: Use Network.Interpolation or Network.Flags

public Sandbox.NetworkMode Sandbox.GameObject.NetworkMode { get; set; }

How should this object be networked to other clients? By default, a `Sandbox.GameObject` will be networked as part of the `Sandbox.GameObject.Scene` snapshot.

public string Sandbox.GameObject.PrefabInstanceSource { get; set; }

public Sandbox.GameObject Sandbox.GameObject.Root { get; set; }

Return the root GameObject. The root is the object that is parented to the scene - which could very much be this object.

public Vector3 Sandbox.GameObject.WorldPosition { get; set; }

The world position of the game object.

public Rotation Sandbox.GameObject.WorldRotation { get; set; }

The world rotation of the game object.

public Vector3 Sandbox.GameObject.WorldScale { get; set; }

The world scale of the game object.

public Transform Sandbox.GameObject.WorldTransform { get; set; }

The world transform of the game object.

Metadata

FieldValue
NamespaceSandbox
Typeclass
AssemblySandbox.Engine
Doc IDT:Sandbox.GameObject

On this page

Constructorspublic GameObject()public GameObject(Sandbox.GameObject parent, System.Boolean enabled = True, System.String name = null)public GameObject(System.Boolean enabled, System.String name)public GameObject(System.Boolean enabled)public GameObject(System.String name)Methodsprotected System.Void __rpc_Wrapper(Sandbox.WrappedMethod m, System.Object[] argumentList)protected System.Void __rpc_Wrapper(Sandbox.WrappedMethod m, T[] argument)protected T __sync_GetValue(Sandbox.WrappedPropertyGet`1<T> p)protected System.Void __sync_SetValue(Sandbox.WrappedPropertySet`1<T> p)public T AddComponent(System.Boolean startEnabled = True)public System.Void AddSibling(Sandbox.GameObject go, System.Boolean before, System.Boolean keepWorldPosition = True)public System.Void BreakFromPrefab()public System.Void Clear()public Sandbox.GameObject Clone()public Sandbox.GameObject Clone(Sandbox.CloneConfig cloneConfig)public Sandbox.GameObject Clone(Sandbox.GameObject parent, Vector3 position, Rotation rotation, Vector3 scale)public static Sandbox.GameObject Clone(Sandbox.PrefabFile prefabFile, System.Nullable`1<Sandbox.CloneConfig> config = null)public static Sandbox.GameObject Clone(Sandbox.PrefabFile prefabFile, Transform transform, Sandbox.GameObject parent = null, System.Boolean startEnabled = True, System.String name = null)public static Sandbox.GameObject Clone(System.String prefabPath, System.Nullable`1<Sandbox.CloneConfig> config = null)public static Sandbox.GameObject Clone(System.String prefabPath, Transform transform, Sandbox.GameObject parent = null, System.Boolean startEnabled = True, System.String name = null)public Sandbox.GameObject Clone(Transform transform, Sandbox.GameObject parent = null, System.Boolean startEnabled = True, System.String name = null)public Sandbox.GameObject Clone(Vector3 position, Rotation rotation, Vector3 scale)public Sandbox.GameObject Clone(Vector3 position, Rotation rotation)public Sandbox.GameObject Clone(Vector3 position)public virtual System.Void Deserialize(System.Text.Json.Nodes.JsonObject node, Sandbox.GameObject.DeserializeOptions options)public virtual System.Void Deserialize(System.Text.Json.Nodes.JsonObject node)public virtual System.Void Destroy()public System.Void DestroyImmediate()public virtual System.Void EditLog(System.String name, System.Object source)public System.Collections.Generic.IEnumerable`1<Sandbox.GameObject> GetAllObjects(System.Boolean enabled)public BBox GetBounds()public T GetComponent(System.Boolean includeDisabled = False)public T GetComponentInChildren(System.Boolean includeDisabled = False, System.Boolean includeSelf = True)public T GetComponentInParent(System.Boolean includeDisabled = False, System.Boolean includeSelf = True)public System.Collections.Generic.IEnumerable`1<T> GetComponents(System.Boolean includeDisabled = False)public System.Collections.Generic.IEnumerable`1<T> GetComponentsInChildren(System.Boolean includeDisabled = False, System.Boolean includeSelf = True)public System.Collections.Generic.IEnumerable`1<T> GetComponentsInParent(System.Boolean includeDisabled = False, System.Boolean includeSelf = True)public BBox GetLocalBounds()public Sandbox.GameObject GetNextSibling(System.Boolean enabledOnly)public T GetOrAddComponent(System.Boolean startEnabled = True)public static Sandbox.GameObject GetPrefab(System.String prefabFilePath)public System.Boolean IsAncestor(Sandbox.GameObject ancestor)public System.Boolean IsDescendant(Sandbox.GameObject decendant)public static override System.Object JsonRead(System.Text.Json.Utf8JsonReader reader, System.Type targetType)public static override System.Void JsonWrite(System.Object value, System.Text.Json.Utf8JsonWriter writer)public System.Void MakeNameUnique()public System.Boolean NetworkSpawn()public System.Boolean NetworkSpawn(Sandbox.Connection owner)public System.Boolean NetworkSpawn(Sandbox.NetworkSpawnOptions options)public System.Boolean NetworkSpawn(System.Boolean enabled, Sandbox.Connection owner)public Sandbox.SoundHandle PlaySound(Sandbox.SoundEvent sound, Vector3 positionOffset = null)public virtual System.Void RunEvent(System.Action`1<T> action, Sandbox.FindMode find = 69)public virtual System.Text.Json.Nodes.JsonObject Serialize(Sandbox.GameObject.SerializeOptions options = null)public System.Void SetParent(Sandbox.GameObject value, System.Boolean keepWorldPosition = True)public System.Void SetPrefabSource(System.String prefabSource)public System.Void StopAllSounds(System.Single fadeOutTime = 0)public System.Void UpdateFromPrefab()Propertiespublic System.Boolean Sandbox.GameObject.Active { get; set; }public System.Collections.Generic.List`1<Sandbox.GameObject> Sandbox.GameObject.Children { get; set; }public virtual sealed Sandbox.ComponentList Sandbox.GameObject.Components { get; set; }public Sandbox.DebugOverlaySystem Sandbox.GameObject.DebugOverlay { get; set; }public System.Boolean Sandbox.GameObject.Enabled { get; set; }public System.Threading.CancellationToken Sandbox.GameObject.EnabledToken { get; set; }public Sandbox.GameObjectFlags Sandbox.GameObject.Flags { get; set; }public System.Boolean Sandbox.GameObject.HasGimzoHandle { get; set; }public System.Boolean Sandbox.GameObject.HasGizmoHandle { get; set; }public System.Guid Sandbox.GameObject.Id { get; set; }public System.Boolean Sandbox.GameObject.IsDeserializing { get; set; }public System.Boolean Sandbox.GameObject.IsDestroyed { get; set; }public System.Boolean Sandbox.GameObject.IsNetworkRoot { get; set; }public System.Boolean Sandbox.GameObject.IsPrefabInstance { get; set; }public System.Boolean Sandbox.GameObject.IsPrefabInstanceRoot { get; set; }public System.Boolean Sandbox.GameObject.IsProxy { get; set; }public System.Boolean Sandbox.GameObject.IsRoot { get; set; }public virtual System.Boolean Sandbox.GameObject.IsValid { get; set; }public Vector3 Sandbox.GameObject.LocalPosition { get; set; }public Rotation Sandbox.GameObject.LocalRotation { get; set; }public Vector3 Sandbox.GameObject.LocalScale { get; set; }public Transform Sandbox.GameObject.LocalTransform { get; set; }public System.String Sandbox.GameObject.Name { get; set; }public Sandbox.GameObject.NetworkAccessor Sandbox.GameObject.Network { get; set; }public System.Boolean Sandbox.GameObject.Networked { get; set; }public System.Boolean Sandbox.GameObject.NetworkInterpolation { get; set; }public Sandbox.NetworkMode Sandbox.GameObject.NetworkMode { get; set; }public Sandbox.GameObject Sandbox.GameObject.Parent { get; set; }public System.String Sandbox.GameObject.PrefabInstanceSource { get; set; }public Sandbox.GameObject Sandbox.GameObject.Root { get; set; }public Sandbox.GameObject.NetworkAccessor Sandbox.GameObject.RootNetwork { get; set; }public Sandbox.Scene Sandbox.GameObject.Scene { get; set; }public Sandbox.GameTags Sandbox.GameObject.Tags { get; set; }public Sandbox.GameTransform Sandbox.GameObject.Transform { get; set; }public Vector3 Sandbox.GameObject.WorldPosition { get; set; }public Rotation Sandbox.GameObject.WorldRotation { get; set; }public Vector3 Sandbox.GameObject.WorldScale { get; set; }public Transform Sandbox.GameObject.WorldTransform { get; set; }Metadata