Skip to content

StateComp

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:32

Fields added by state(): a small finite state machine.

optional add(this): void

Defined in: packages/threeplay/src/core/types.ts:63

Called when the object enters the scene (or when used on a live object).

GameObj

void

Comp.add


optional destroy(this): void

Defined in: packages/threeplay/src/core/types.ts:69

Called when the object is destroyed or the component removed.

GameObj

void

Comp.destroy


enterState(name, …args): void

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:37

Leaves the current state (running its onStateEnd handlers) and enters name, passing args to its enter handlers. Throws for names outside allowed.

string

…unknown[]

void


optional fixedUpdate(this): void

Defined in: packages/threeplay/src/core/types.ts:67

Called at the fixed physics rate (50 Hz by default).

GameObj

void

Comp.fixedUpdate


optional inspect(this): string | null | undefined

Defined in: packages/threeplay/src/core/types.ts:71

Short status line shown by the debug inspector.

GameObj

string | null | undefined

Comp.inspect


onStateEnd(name, fn): EventController

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:44

Runs when name is left.

string

() => void

EventController


onStateEnter(name, fn): EventController

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:42

Runs when name is entered. The initial state is entered on the first frame, so handlers registered right after add([...]) still see it.

string

(…args) => void

EventController


onStateUpdate(name, fn): EventController

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:46

Runs every frame while name is the current state (not while the object is paused).

string

() => void

EventController


optional update(this): void

Defined in: packages/threeplay/src/core/types.ts:65

Called once per frame.

GameObj

void

Comp.update

optional conflicts?: string[]

Defined in: packages/threeplay/src/core/types.ts:61

Ids of components that can’t be on the same object (checked both ways).

Comp.conflicts


id: "state"

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:33

Unique name. Two components with the same id replace each other.

Comp.id


optional require?: string[]

Defined in: packages/threeplay/src/core/types.ts:59

Ids of components that must be present on the object.

Comp.require


state: string

Defined in: packages/threeplay/src/plugins/gameplay/types.ts:35

Name of the current state. Assigning to it calls enterState.