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.
Related Guides
Broader workflow and conceptual references connected to this API.
If you want a specific file/asset type to have a custom Thumbnail/Inspector Preview, you can simply create an AssetPreview. An AssetPreview initializes a SceneWorld and SceneCamera, rendering the Camera to the Preview output, so all you need to do is populate it and/or position the Camera to your liking.
There are various interfaces that can be given to components for specific purposes.
A Component is added to a GameObject to provide functionality. This functionality can vary wildly.
A GameObject represents an object in the scene world. It contains a few different elements.
Allows a GameObject's Components to listen to changes in ownership state.
A Vector is just a set of numbers that describe a position or a direction in space.
Constructors
Showing 5 constructors
No results match this filter.
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: FalseincludeSelf: Default: True
public T GetComponentInParent(bool includeDisabled = False, bool includeSelf = True)
Get component on this GameObject and on ancestor GameObjects
Parameters
includeDisabled: Default: FalseincludeSelf: 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: FalseincludeSelf: 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: FalseincludeSelf: 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()
No results match this filter.
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 Sandbox.GameObjectFlags Sandbox.GameObject.Flags { get; set; }
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 Sandbox.GameObject.NetworkAccessor Sandbox.GameObject.Network { get; set; }
Access network information for this GameObject.
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 Sandbox.GameObject Sandbox.GameObject.Parent { get; set; }
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 Sandbox.GameObject.NetworkAccessor Sandbox.GameObject.RootNetwork { get; set; }
public Sandbox.Scene Sandbox.GameObject.Scene { get; set; }
The scene that this GameObject is in.
public Sandbox.GameTags Sandbox.GameObject.Tags { get; set; }
public Sandbox.GameTransform Sandbox.GameObject.Transform { get; set; }
Our position relative to our parent, or the scene if we don't have any parent.
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.
No results match this filter.
Metadata
| Field | Value |
|---|---|
| Namespace | Sandbox |
| Type | class |
| Assembly | Sandbox.Engine |
| Doc ID | T:Sandbox.GameObject |