Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/facepunch/sbox-public/llms.txt

Use this file to discover all available pages before exploring further.

GameObject is the fundamental building block of every s&box scene. Every object you place in a scene — a character, a prop, a trigger volume, a light — is a GameObject. Functionality is added by attaching Component instances to it. This page covers the full public API: constructors, core properties, hierarchy management, component access, cloning, and lifecycle methods.
GameObject is a partial class split across several files in the engine source. All public members documented here are safe to use from game code.

Constructors

You can create a GameObject directly in code. The newly created object is automatically added to the active scene (Game.ActiveScene).
// Named, enabled by default
var go = new GameObject("Player");

// Disabled on creation
var go = new GameObject(false, "Player");

// With an explicit parent
var child = new GameObject(parentGo, enabled: true, "Weapon");
GameObject(string name)
constructor
Creates an enabled GameObject with the given name, parented to the active scene.
GameObject(bool enabled, string name)
constructor
Creates a GameObject with an explicit enabled state and name.
GameObject(GameObject parent, bool enabled, string name)
constructor
Creates a GameObject with a specific parent, enabled state, and name. When parent is null, the active scene is used as the parent.
GameObject()
constructor
Creates an enabled GameObject named "GameObject".

Core properties

Name
string
The display name of the object. Used in the editor hierarchy and when searching for objects by name. Setting Name to null falls back to "Untitled Object".
go.Name = "My Object";
Log.Info(go.Name); // "My Object"
Scene
Scene
The Scene this GameObject belongs to. Read-only from game code — a GameObject is always in exactly one scene.
Transform
GameTransform
The transform of this object, describing its position, rotation, and scale relative to its parent. See GameTransform for position/rotation/scale accessors.
go.Transform.World = new Transform(Vector3.Up * 100f);
go.Transform.Local = Transform.Zero;
Enabled
bool
Whether this GameObject is enabled. Disabling a GameObject also disables all of its components and prevents them from ticking. The object remains in the scene hierarchy.
go.Enabled = false; // disable without destroying
Active
bool
true when this GameObject is truly active in the scene: it is enabled, all ancestor GameObjects are enabled, it belongs to a scene, and it is not network-culled. Use Active rather than Enabled to check whether components will actually tick.
Parent
GameObject
The parent of this GameObject. Setting Parent to null re-parents to the scene root. Cannot be set on a Scene itself.
child.Parent = anotherGo;
child.Parent = null; // move to scene root
Children
List<GameObject>
The direct children of this GameObject. Read directly or enumerate with foreach.
IsRoot
bool
true when this GameObject is parented directly to the scene (has no GameObject parent).
Root
GameObject
Returns the topmost GameObject ancestor that is parented to the scene. Returns this when IsRoot is true.
IsValid
bool
true when this GameObject has not been destroyed and belongs to a scene. Always check IsValid (or the go.IsValid() extension) before using an object you didn’t just create.
IsDestroyed
bool
true when Destroy() has been called or the object is already fully destroyed. An object may report IsDestroyed = true for one frame before it is removed.
Components
ComponentList
Access to all components on this GameObject. Use Components.Get<T>(), Components.GetAll<T>(), etc. for low-level access, or use the shortcut methods on GameObject directly (see below).
Tags
GameTags
The tag set for this GameObject. Tags are case-insensitive strings that propagate from parent to child. See the Tags section for details.
EnabledToken
CancellationToken
A CancellationToken that is cancelled when this GameObject is disabled or destroyed. Useful for async code that should stop when the object is gone.

Hierarchy methods

SetParent

public void SetParent(GameObject value, bool keepWorldPosition = true)
Re-parents this GameObject. When keepWorldPosition is true (the default), the world-space Transform is preserved; the local transform is recalculated to match. Set keepWorldPosition to false to keep the local transform unchanged instead.
value
GameObject
required
The new parent. Pass null to move to the scene root.
keepWorldPosition
bool
default:"true"
When true, the object stays in the same world-space position. When false, the local transform is preserved.

AddSibling

public void AddSibling(GameObject go, bool before, bool keepWorldPosition = true)
Inserts go as a sibling of this GameObject in the parent’s child list.

IsAncestor / IsDescendant

public bool IsAncestor(GameObject ancestor)
public bool IsDescendant(GameObject descendant)
Hierarchy relationship queries.

GetAllObjects

public IEnumerable<GameObject> GetAllObjects(bool enabled)
Returns this GameObject and all descendants, optionally filtering to only enabled objects.

GetNextSibling

public GameObject GetNextSibling(bool enabledOnly)
Returns the next sibling in the parent’s child list, or null if there is none.

Component methods

These are convenience wrappers around Components. For advanced queries use Components directly with a FindMode flag.

AddComponent

public T AddComponent<T>(bool startEnabled = true) where T : Component, new()
Creates and attaches a new component of type T to this GameObject.
startEnabled
bool
default:"true"
Whether the component starts enabled.
var rb = go.AddComponent<Rigidbody>();
var light = go.AddComponent<PointLight>(startEnabled: false);

GetOrAddComponent

public T GetOrAddComponent<T>(bool startEnabled = true) where T : Component, new()
Returns an existing component of type T if one exists, otherwise creates and attaches one.

GetComponent

public T GetComponent<T>(bool includeDisabled = false)
Returns the first component of type T on this GameObject. Returns null when none is found.
includeDisabled
bool
default:"false"
When true, also searches disabled components.
var cam = go.GetComponent<CameraComponent>();
if (cam is not null) { ... }

GetComponents

public IEnumerable<T> GetComponents<T>(bool includeDisabled = false)
Returns all components of type T on this GameObject.

GetComponentInChildren

public T GetComponentInChildren<T>(bool includeDisabled = false, bool includeSelf = true)
Returns the first component of type T found on this GameObject or any descendant.
includeDisabled
bool
default:"false"
When true, searches disabled components and disabled child objects.
includeSelf
bool
default:"true"
When true, also checks this GameObject before searching children.

GetComponentsInChildren

public IEnumerable<T> GetComponentsInChildren<T>(bool includeDisabled = false, bool includeSelf = true)
Returns all components of type T found on this GameObject and all descendants.

GetComponentInParent

public T GetComponentInParent<T>(bool includeDisabled = false, bool includeSelf = true)
Returns the first component of type T found on this GameObject or any ancestor.

GetComponentsInParent

public IEnumerable<T> GetComponentsInParent<T>(bool includeDisabled = false, bool includeSelf = true)
Returns all components of type T found on this GameObject and all ancestors.

Cloning

Cloning creates a deep copy of a GameObject and its entire component and child hierarchy, with all internal references (component-to-component, GameObject-to-GameObject) rewired to the cloned copies.

Clone (instance)

public GameObject Clone()
public GameObject Clone(Vector3 position)
public GameObject Clone(Vector3 position, Rotation rotation)
public GameObject Clone(Vector3 position, Rotation rotation, Vector3 scale)
public GameObject Clone(Transform transform, GameObject parent = null, bool startEnabled = true, string name = null)
public GameObject Clone(in CloneConfig cloneConfig)
Creates a deep copy of this GameObject at the specified transform.
// Duplicate an existing object at a new position
var copy = existingGo.Clone(new Vector3(0, 0, 100));

// Full control via CloneConfig
var cfg = new CloneConfig(new Transform(spawnPos, spawnRot), parentGo, startEnabled: true);
var copy = existingGo.Clone(cfg);

Clone (static — from prefab path)

public static GameObject Clone(string prefabPath, CloneConfig? config = default)
public static GameObject Clone(string prefabPath, Transform transform, GameObject parent = null, bool startEnabled = true, string name = null)
Loads a prefab by resource path and instantiates it.
var bullet = GameObject.Clone("prefabs/bullet.prefab", Transform.Zero);

Clone (static — from PrefabFile)

public static GameObject Clone(PrefabFile prefabFile, CloneConfig? config = default)
public static GameObject Clone(PrefabFile prefabFile, Transform transform, GameObject parent = null, bool startEnabled = true, string name = null)
Instantiates a prefab from a PrefabFile resource reference.

CloneConfig

CloneConfig is a struct that controls cloning parameters.
Transform
Transform
World-space transform for the root of the clone.
Parent
GameObject
Optional parent for the clone. When null, the clone is placed at the scene root.
StartEnabled
bool
Whether the clone starts enabled. Defaults to true.
Name
string
Optional name override for the clone’s root GameObject. When null, the original name is used.

Lifecycle and destruction

Destroy

public virtual void Destroy()
Marks this GameObject for destruction. The object and all its children and components are fully removed at the start of the next frame. Safe to call multiple times — subsequent calls are no-ops.
go.Destroy();
// go.IsDestroyed is now true; avoid using go after this point

DestroyImmediate

public void DestroyImmediate()
Destroys this GameObject synchronously in the current frame. Use with caution — any code that still holds a reference to this object may encounter errors.
Prefer Destroy() over DestroyImmediate(). Immediate destruction can cause unexpected behaviour when other systems still reference the object within the same frame.

Clear

public void Clear()
Destroys all components and all child GameObjects without destroying this GameObject itself.

Tags

Tags are case-insensitive strings attached to a GameObject. A child inherits tags from all of its ancestors — a tag set on a parent is visible on all children via Tags.Has().
go.Tags.Add("player");
go.Tags.Add("friendly", "damageable");

bool isPlayer = go.Tags.Has("player");        // true
bool isAll    = go.Tags.HasAll(["player", "friendly"]); // true

go.Tags.Remove("friendly");
go.Tags.RemoveAll();
Tags.Add(string tag)
void
Adds a single tag. Tags are normalised to lowercase.
Tags.Add(params string[] tags)
void
Adds multiple tags at once.
Tags.Remove(string tag)
void
Removes a tag from this object. Has no effect on inherited ancestor tags.
Tags.RemoveAll()
void
Removes all tags set directly on this object.
Tags.Has(string tag)
bool
Returns true when this object or any ancestor has the tag.
Tags.Has(string tag, bool includeAncestors)
bool
Returns true when this object has the tag. Pass includeAncestors: false to ignore inherited tags.
Tags.TryGetAll()
IEnumerable<string>
Returns all tags including those inherited from ancestors.

Bounds helpers

These methods are relatively slow and should not be called every frame. They aggregate bounds from all IHasBounds components in the hierarchy.
public BBox GetBounds()      // world-space bounds
public BBox GetLocalBounds() // local-space bounds

FindMode enum

FindMode is a flags enum used in Components.GetAll<T>() and related methods. Combine flags with |.
Enabled
flag
Include enabled components only.
Disabled
flag
Include disabled components only.
InSelf
flag
Search on this GameObject.
InParent
flag
Search on the immediate parent.
InAncestors
flag
Search on all ancestors.
InChildren
flag
Search on immediate children.
InDescendants
flag
Search on all descendants.
Commonly used composite values:
ValueMeaning
EnabledInSelfEnabled components on this object
EnabledInSelfAndDescendantsDefault for most searches
EverythingInSelfEnabled and disabled components on this object

See also

Component

Base class for all components that attach to a GameObject.

Scene

The container that holds all GameObjects and provides scene-wide queries.

Scripting basics

Practical guide to writing your first component.

Build docs developers (and LLMs) love