GameObjectclass

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.

object→GameObject
Namespace
Sandbox
Assembly
Sandbox.Engine
Declaration
public class Sandbox.GameObject

Constructors5

Showing 5 constructors

Methods59

Showing 59 methods

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

ParameterTypeDescription
pWrappedPropertyGet<T>—
Returns:T—

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

ParameterTypeDescription
pWrappedPropertySet<T>—
Returns:void—

public T AddComponent(bool startEnabled = True)PUBLIC

Add a component to this GameObject

ParameterTypeDescription
startEnabled = Truebool—
Returns:T—

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

ParameterTypeDescription
goGameObject—
beforebool—
keepWorldPosition = Truebool—
Returns:void—

public void BreakFromPrefab()PUBLIC

We are cloned from a prefab. Stop that.

Returns:void—

public void Clear()PUBLIC

Destroy all components and child objects

Returns:void—

public virtual void Destroy()PUBLICVIRTUAL

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

Returns:void—

public void DestroyImmediate()PUBLIC

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.

Returns:void—

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

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

ParameterTypeDescription
namestring—
sourceobject—
Returns:void—

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

ParameterTypeDescription
enabledbool—
Returns:IEnumerable<GameObject>—

public BBox GetBounds()PUBLIC

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

Returns:BBox—

public T GetComponent(bool includeDisabled = False)PUBLIC

Get a component on this GameObject

ParameterTypeDescription
includeDisabled = Falsebool—
Returns:T—

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

Get component on this GameObject or on descendant GameObjects

ParameterTypeDescription
includeDisabled = Falsebool—
includeSelf = Truebool—
Returns:T—

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

Get component on this GameObject and on ancestor GameObjects

ParameterTypeDescription
includeDisabled = Falsebool—
includeSelf = Truebool—
Returns:T—

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

Get components on this GameObject

ParameterTypeDescription
includeDisabled = Falsebool—
Returns:IEnumerable<T>—

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

Get components on this GameObject and on descendant GameObjects

ParameterTypeDescription
includeDisabled = Falsebool—
includeSelf = Truebool—
Returns:IEnumerable<T>—

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

Get components on this GameObject and on ancestor GameObjects

ParameterTypeDescription
includeDisabled = Falsebool—
includeSelf = Truebool—
Returns:IEnumerable<T>—

public BBox GetLocalBounds()PUBLIC

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

Returns:BBox—

public Sandbox.GameObject GetNextSibling(bool enabledOnly)PUBLIC

Get the GameObject after us,

ParameterTypeDescription
enabledOnlybool—
Returns:GameObject—

public T GetOrAddComponent(bool startEnabled = True)PUBLIC

Add a component to this GameObject

ParameterTypeDescription
startEnabled = Truebool—
Returns:T—

public static Sandbox.GameObject GetPrefab(string prefabFilePath)PUBLICSTATIC

Get the GameObject of a prefab from file path

ParameterTypeDescription
prefabFilePathstring—
Returns:GameObject—

public bool IsAncestor(Sandbox.GameObject ancestor)PUBLIC

Returns true if the passed in object is an ancestor

ParameterTypeDescription
ancestorGameObject—
Returns:bool—

public bool IsDescendant(Sandbox.GameObject decendant)PUBLIC

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

ParameterTypeDescription
decendantGameObject—
Returns:bool—

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

ParameterTypeDescription
readerUtf8JsonReader—
targetTypeType—
Returns:object—

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

ParameterTypeDescription
valueobject—
writerUtf8JsonWriter—
Returns:void—

public void MakeNameUnique()PUBLIC

Returns:void—

public Sandbox.SoundHandle PlaySound(Sandbox.SoundEvent sound, Vector3 positionOffset = null)PUBLIC

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.

ParameterTypeDescription
soundSoundEvent—
positionOffset = nullVector3—
Returns:SoundHandle—

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

ParameterTypeDescription
actionAction<T>—
find = 69FindMode—
Returns:void—

public virtual System.Text.Json.Nodes.JsonObject Serialize(Sandbox.GameObject.SerializeOptions options = null)PUBLICVIRTUAL

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.

ParameterTypeDescription
options = nullSerializeOptions—
Returns:JsonObject—

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

ParameterTypeDescription
valueGameObject—
keepWorldPosition = Truebool—
Returns:void—

public void SetPrefabSource(string prefabSource)PUBLICOBSOLETE

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

ParameterTypeDescription
prefabSourcestring—
Returns:void—

public void StopAllSounds(float fadeOutTime = 0)PUBLIC

Stop any sounds playing on this GameObject

ParameterTypeDescription
fadeOutTime = 0float—
Returns:void—

public void UpdateFromPrefab()PUBLICPER-FRAME

Returns:void—

Properties39

Showing 39 properties

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

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.

Returns:bool—

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

Is this gameobject enabled?

Returns:bool—

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

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

Returns:CancellationToken—

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

Obsolete: Use HasGizmoHandle

Returns:bool—

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

Returns:bool—

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

Returns:Guid—

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

True if this GameObject is being deserialized right now

Returns:bool—

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

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

Returns:bool—

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

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

Returns:bool—

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

This GameObject is part of a prefab instance.

Returns:bool—

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

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

Returns:bool—

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

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.

Returns:bool—

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

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

Returns:bool—

public bool Sandbox.GameObject.IsStatic { get; set; }PUBLICGETSET

This object never moves during gameplay, letting rendering, physics and navmesh make static optimizations. Children inherit this via `Sandbox.GameObjectFlags.Static` on any ancestor.

Returns:bool—

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

True if the GameObject is not destroyed

Returns:bool—

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

The local position of the game object.

Returns:Vector3—

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

The local rotation of the game object.

Returns:Rotation—

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

The local scale of the game object.

Returns:Vector3—

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

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

Returns:string—

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

OBSOLETE: Use NetworkMode instead.

Obsolete: Use GameObject.NetworkMode

Returns:bool—

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

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

Returns:bool—

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

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.

Returns:NetworkMode—

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

Returns:string—

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

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

Returns:GameObject—

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

The world position of the game object.

Returns:Vector3—

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

The world rotation of the game object.

Returns:Rotation—

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

The world scale of the game object.

Returns:Vector3—

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)protected System.Void __rpc_Wrapper(Sandbox.WrappedMethod m, T1 a1)protected System.Void __rpc_Wrapper(Sandbox.WrappedMethod m, T[] argument)protected System.Void __rpc_Wrapper(Sandbox.WrappedMethod m, T1 a1, T2 a2)protected System.Void __rpc_Wrapper(Sandbox.WrappedMethod m, T1 a1, T2 a2, T3 a3)protected System.Void __rpc_Wrapper(Sandbox.WrappedMethod m, T1 a1, T2 a2, T3 a3, T4 a4)protected System.Void __rpc_Wrapper(Sandbox.WrappedMethod m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5)protected System.Void __rpc_Wrapper(Sandbox.WrappedMethod m, T1 a1, T2 a2, T3 a3, T4 a4, T5 a5, T6 a6)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 System.Boolean Sandbox.GameObject.IsStatic { 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