Skip to content

API Class GameObject

github-actions[bot] edited this page Dec 1, 2026 · 4 revisions

Class: GameObject

Defined in: src/engine/core/GameObject.ts:30

A node in the scene graph (ADR 0008). A lightweight handle to an internal entity; game code never sees the entity id. Handles become invalid once the node is destroyed (at the end of the frame destroy was called in).

Accessors

active

Get Signature

get active(): boolean;

Defined in: src/engine/core/GameObject.ts:108

The node's own active flag.

Returns

boolean


activeInHierarchy

Get Signature

get activeInHierarchy(): boolean;

Defined in: src/engine/core/GameObject.ts:112

Active only if this node and all its ancestors are active.

Returns

boolean


children

Get Signature

get children(): GameObject[];

Defined in: src/engine/core/GameObject.ts:141

Returns

GameObject[]


id

Get Signature

get id(): string;

Defined in: src/engine/core/GameObject.ts:98

Stable id from scene data (empty for nodes created at runtime).

Returns

string


isComponentNode

Get Signature

get isComponentNode(): boolean;

Defined in: src/engine/core/GameObject.ts:115

True for component nodes: child nodes that host components on behalf of their parent (ADR 0009).

Returns

boolean


isSceneNode

Get Signature

get isSceneNode(): boolean;

Defined in: src/engine/core/GameObject.ts:117

Returns

boolean


isValid

Get Signature

get isValid(): boolean;

Defined in: src/engine/core/GameObject.ts:89

False once the node has been destroyed.

Returns

boolean


name

Get Signature

get name(): string;

Defined in: src/engine/core/GameObject.ts:100

Returns

string

Set Signature

set name(value): void;

Defined in: src/engine/core/GameObject.ts:101

Parameters
value

string

Returns

void


parent

Get Signature

get parent(): GameObject | null;

Defined in: src/engine/core/GameObject.ts:135

Returns

GameObject | null


scene

Get Signature

get scene(): GameObject | null;

Defined in: src/engine/core/GameObject.ts:120

The nearest ancestor scene node, or null for persistent nodes and the root (ADR 0016).

Returns

GameObject | null


tags

Get Signature

get tags(): string[];

Defined in: src/engine/core/GameObject.ts:103

Returns

string[]

Set Signature

set tags(value): void;

Defined in: src/engine/core/GameObject.ts:104

Parameters
value

string[]

Returns

void


transform

Get Signature

get transform(): Transform | null;

Defined in: src/engine/core/GameObject.ts:130

Returns

Transform | null

Methods

addBehavior()

addBehavior<T>(type, init?): T;

Defined in: src/engine/core/GameObject.ts:176

Attach a component to this node. init values that are another World's nodes or components throw (ADR 0032). A component registered for other Worlds (@behavior(id, { worlds }), ADR 0033) isn't attached: you get a detached instance that never runs and that getBehavior doesn't find (see _componentAllowedIn). UI components (UICanvas, UIPanel, UIText, UIImage, UIButton, UIInputField…) throw: only a UIView rendering its component makes them (ADR 0421, amended by 0423).

Type Parameters

T

T extends Component

Parameters

type

ConcreteComponentType<T>

init?

ComponentInit<T>

Returns

T


addChildBehavior()

addChildBehavior<T>(type, options?): T;

Defined in: src/engine/core/GameObject.ts:188

Attach a component on a new component node under this node (ADR 0009). The component's owner is this node; the component node has its own transform for offsets.

Type Parameters

T

T extends Component

Parameters

type

ConcreteComponentType<T>

options?
init?

ComponentInit<T>

name?

string

position?

Vec3Input

Returns

T


addComponent()

addComponent<T>(type, init?): T;

Defined in: src/engine/core/GameObject.ts:252

Type Parameters

T

T extends Component

Parameters

type

ConcreteComponentType<T>

init?

ComponentInit<T>

Returns

T


addData()

addData<S>(def, init?): DataView<S>;

Defined in: src/engine/core/GameObject.ts:260

Type Parameters

S

S extends Schema

Parameters

def

DataComponentDef<S>

init?

Partial<Record<keyof S, number | boolean>>

Returns

DataView<S>


find()

find(path): GameObject | null;

Defined in: src/engine/core/GameObject.ts:157

Find a descendant by slash-separated name path, e.g. "Weapon/Muzzle".

Parameters

path

string

Returns

GameObject | null


getBehavior()

getBehavior<T>(type): T | null;

Defined in: src/engine/core/GameObject.ts:199

First component of type attached directly to this node.

Type Parameters

T

T extends Component

Parameters

type

ComponentType<T>

Returns

T | null


getBehaviorInChildren()

getBehaviorInChildren<T>(type, includeInactive?): T | null;

Defined in: src/engine/core/GameObject.ts:224

First component of type on this node or any descendant (depth-first).

Type Parameters

T

T extends Component

Parameters

type

ComponentType<T>

includeInactive?

boolean = false

Returns

T | null


getBehaviorInComponents()

getBehaviorInComponents<T>(type): T | null;

Defined in: src/engine/core/GameObject.ts:212

Attached components plus those on this node's component-node children (ADR 0009).

Type Parameters

T

T extends Component

Parameters

type

ComponentType<T>

Returns

T | null


getBehaviorInParent()

getBehaviorInParent<T>(type): T | null;

Defined in: src/engine/core/GameObject.ts:237

First component of type on this node or any ancestor.

Type Parameters

T

T extends Component

Parameters

type

ComponentType<T>

Returns

T | null


getBehaviors()

getBehaviors<T>(type): T[];

Defined in: src/engine/core/GameObject.ts:206

All components of type attached directly to this node.

Type Parameters

T

T extends Component

Parameters

type

ComponentType<T>

Returns

T[]


getComponent()

getComponent<T>(type): T | null;

Defined in: src/engine/core/GameObject.ts:253

Type Parameters

T

T extends Component

Parameters

type

ComponentType<T>

Returns

T | null


getComponentInChildren()

getComponentInChildren<T>(type, includeInactive?): T | null;

Defined in: src/engine/core/GameObject.ts:255

Type Parameters

T

T extends Component

Parameters

type

ComponentType<T>

includeInactive?

boolean = false

Returns

T | null


getComponentInParent()

getComponentInParent<T>(type): T | null;

Defined in: src/engine/core/GameObject.ts:256

Type Parameters

T

T extends Component

Parameters

type

ComponentType<T>

Returns

T | null


getComponents()

getComponents<T>(type): T[];

Defined in: src/engine/core/GameObject.ts:254

Type Parameters

T

T extends Component

Parameters

type

ComponentType<T>

Returns

T[]


getData()

getData<S>(def): DataView<S> | null;

Defined in: src/engine/core/GameObject.ts:267

Type Parameters

S

S extends Schema

Parameters

def

DataComponentDef<S>

Returns

DataView<S> | null


hasData()

hasData(def): boolean;

Defined in: src/engine/core/GameObject.ts:273

Parameters

def

DataComponentDef

Returns

boolean


hasTag()

hasTag(tag): boolean;

Defined in: src/engine/core/GameObject.ts:105

Parameters

tag

string

Returns

boolean


removeBehavior()

removeBehavior(component): void;

Defined in: src/engine/core/GameObject.ts:246

Queue a component on this node for removal at the end of the frame.

Parameters

component

Component

Returns

void


removeData()

removeData(def): void;

Defined in: src/engine/core/GameObject.ts:278

Parameters

def

DataComponentDef

Returns

void


setActive()

setActive(active): void;

Defined in: src/engine/core/GameObject.ts:109

Parameters

active

boolean

Returns

void


setParent()

setParent(parent, options?): boolean;

Defined in: src/engine/core/GameObject.ts:150

Reparent. By default the world transform is kept. Returns false if it would create a cycle. Throws for a parent in another World (ADR 0032).

Parameters

parent

GameObject

options?
keepWorldTransform?

boolean

Returns

boolean


toString()

toString(): string;

Defined in: src/engine/core/GameObject.ts:283

Returns

string


create()

static create(name?, options?): GameObject;

Defined in: src/engine/core/GameObject.ts:44

Create an empty node: in the parent's World when one is given, else in the current World (ADR 0032, 0034). Passing a parent is how code after an await stays in its own World.

Parameters

name?

string = "GameObject"

options?
parent?

GameObject | null

transform?

boolean

Returns

GameObject


destroy()

static destroy(target): void;

Defined in: src/engine/core/GameObject.ts:61

Queue a node (with its subtree) or a component for destruction at the end of the frame.

Parameters

target

Component | GameObject

Returns

void


findObjectOfType()

static findObjectOfType<T>(type): T | null;

Defined in: src/engine/core/GameObject.ts:77

First active component of type in the active world.

Type Parameters

T

T extends Component

Parameters

type

ComponentType<T>

Returns

T | null


findObjectsOfType()

static findObjectsOfType<T>(type): T[];

Defined in: src/engine/core/GameObject.ts:82

All active components of type in the active world.

Type Parameters

T

T extends Component

Parameters

type

ComponentType<T>

Returns

T[]


instantiate()

static instantiate(prefabPath, options?): GameObject;

Defined in: src/engine/core/GameObject.ts:56

Instantiate a prefab file (a scene file with one root node, ADR 0013/0016) and return its root: in the parent's World when one is given, else in the current World (ADR 0032, 0034). awake/onEnable run before this returns; start runs next frame. In a behavior, this.instantiate always uses the behavior's own World.

Parameters

prefabPath

string

options?

InstantiateOptions = {}

Returns

GameObject


makePersistent()

static makePersistent(node): void;

Defined in: src/engine/core/GameObject.ts:71

Move a node directly under the World root so it survives scene loads (ADR 0016). Throws for a scene node (a loaded scene or a sub-scene, ADR 0630): under the root a scene node is a loaded scene, which the next replacing load destroys; make the nodes inside it persistent, or list the scene as an autoload.

Parameters

node

GameObject

Returns

void

Clone this wiki locally