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 aGameObject directly in code. The newly created object is automatically added to the active scene (Game.ActiveScene).
Creates an enabled
GameObject with the given name, parented to the active scene.Creates a
GameObject with an explicit enabled state and name.Creates a
GameObject with a specific parent, enabled state, and name. When parent is null, the active scene is used as the parent.Creates an enabled
GameObject named "GameObject".Core properties
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".The
Scene this GameObject belongs to. Read-only from game code — a GameObject is always in exactly one scene.The transform of this object, describing its position, rotation, and scale relative to its parent. See
GameTransform for position/rotation/scale accessors.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.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.The parent of this
GameObject. Setting Parent to null re-parents to the scene root. Cannot be set on a Scene itself.The direct children of this
GameObject. Read directly or enumerate with foreach.true when this GameObject is parented directly to the scene (has no GameObject parent).Returns the topmost
GameObject ancestor that is parented to the scene. Returns this when IsRoot is true.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.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.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).The tag set for this
GameObject. Tags are case-insensitive strings that propagate from parent to child. See the Tags section for details.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
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.
The new parent. Pass
null to move to the scene root.When
true, the object stays in the same world-space position. When false, the local transform is preserved.AddSibling
go as a sibling of this GameObject in the parent’s child list.
IsAncestor / IsDescendant
GetAllObjects
GameObject and all descendants, optionally filtering to only enabled objects.
GetNextSibling
null if there is none.
Component methods
These are convenience wrappers aroundComponents. For advanced queries use Components directly with a FindMode flag.
AddComponent
T to this GameObject.
Whether the component starts enabled.
GetOrAddComponent
T if one exists, otherwise creates and attaches one.
GetComponent
T on this GameObject. Returns null when none is found.
When
true, also searches disabled components.GetComponents
T on this GameObject.
GetComponentInChildren
T found on this GameObject or any descendant.
When
true, searches disabled components and disabled child objects.When
true, also checks this GameObject before searching children.GetComponentsInChildren
T found on this GameObject and all descendants.
GetComponentInParent
T found on this GameObject or any ancestor.
GetComponentsInParent
T found on this GameObject and all ancestors.
Cloning
Cloning creates a deep copy of aGameObject and its entire component and child hierarchy, with all internal references (component-to-component, GameObject-to-GameObject) rewired to the cloned copies.
Clone (instance)
GameObject at the specified transform.
Clone (static — from prefab path)
Clone (static — from PrefabFile)
PrefabFile resource reference.
CloneConfig
CloneConfig is a struct that controls cloning parameters.
World-space transform for the root of the clone.
Optional parent for the clone. When
null, the clone is placed at the scene root.Whether the clone starts enabled. Defaults to
true.Optional name override for the clone’s root
GameObject. When null, the original name is used.Lifecycle and destruction
Destroy
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.
DestroyImmediate
GameObject synchronously in the current frame. Use with caution — any code that still holds a reference to this object may encounter errors.
Clear
GameObjects without destroying this GameObject itself.
Tags
Tags are case-insensitive strings attached to aGameObject. A child inherits tags from all of its ancestors — a tag set on a parent is visible on all children via Tags.Has().
Adds a single tag. Tags are normalised to lowercase.
Adds multiple tags at once.
Removes a tag from this object. Has no effect on inherited ancestor tags.
Removes all tags set directly on this object.
Returns
true when this object or any ancestor has the tag.Returns
true when this object has the tag. Pass includeAncestors: false to ignore inherited tags.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 allIHasBounds components in the hierarchy.
FindMode enum
FindMode is a flags enum used in Components.GetAll<T>() and related methods. Combine flags with |.
Include enabled components only.
Include disabled components only.
Search on this
GameObject.Search on the immediate parent.
Search on all ancestors.
Search on immediate children.
Search on all descendants.
| Value | Meaning |
|---|---|
EnabledInSelf | Enabled components on this object |
EnabledInSelfAndDescendants | Default for most searches |
EverythingInSelf | Enabled 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.