arcade2d
Interface

WorldComponent

world/dependencies.types.ts:194

Extends Component<World, TDeps>

A component attached to the World itself. Use this rather than the lower-level Component interface whenever you're writing a world-scoped system — input samplers, physics broadphases, renderers, audio mixers, scene graphs — both because the name reads better in docs/imports and because the dependency resolver is typed correctly for the world tier (no requireFromWorld, because there's no tier above).

Declaring dependencies

Implement the optional resolveDependencies method to declare what other components this one needs in place. The return value's shape becomes the TDeps generic parameter, which then types the deps argument of every other lifecycle hook.

type PhysicsDeps = { input: InputSystem };

class PhysicsSystem implements WorldComponent<PhysicsDeps> {
  constructor(public readonly host: World) {}

  resolveDependencies(resolver: WorldDependencyResolver): PhysicsDeps {
    return { input: resolver.requireSibling(InputSystem) };
  }

  onAdded({ input }: PhysicsDeps): void { ... }
  onUpdate(update: WorldUpdate, { input }: PhysicsDeps): void { ... }
  onDestroy({ input }: PhysicsDeps): void { ... }
}

Properties

#
enabled?: boolean

Optional gate on the three update hooks (onPreUpdate, onUpdate, onPostUpdate). When explicitly false, the engine skips all three for this component during the world tick — useful for temporarily pausing behaviour (e.g. a freeze powerup) without removing the component and losing its internal state.

Absent or true means "active." The flag does not gate onAdded/onDestroy; those always fire so the host can never end up with a half-attached component.

readonly #
host: World

The host object that this component is attached to.

Methods

#
onAdded(deps: TDeps): void

Lifecycle hook that is called when the component is added to the host object. Should not be called directly.

Parameters

  • deps TDeps

Returns

void
#
onDestroy(deps: TDeps): void

Lifecycle hook that is called when the host object is destroyed. Should not be called directly.

Parameters

  • deps TDeps

Returns

void
#
onPostUpdate(update: WorldUpdate, deps: TDeps): void

Optional lifecycle hook for the post-update phase. Called once per world tick, after every component's onUpdate has run. Use for work that has to observe the world after this tick's behaviour has been applied — camera follow, transform sync, late-frame audit logs.

Parameters

Returns

void
#
onPreUpdate(update: WorldUpdate, deps: TDeps): void

Optional lifecycle hook for the pre-update phase. Called once per world tick, before any component on any host has its onUpdate called. Use for state preparation work that other components' onUpdate will read.

Parameters

Returns

void
#
onUpdate(update: WorldUpdate, deps: TDeps): void

Lifecycle hook for the main update phase. Called once per world tick, after every component's onPreUpdate and before any onPostUpdate.

Parameters

Returns

void
#
resolveDependencies(resolver: WorldDependencyResolver): TDeps

Optional dependency declaration. Called by the engine immediately after the component is registered with the host, before onAdded. The returned object becomes the deps argument threaded into every subsequent lifecycle hook.

If this method throws, the component is removed from the host and the error propagates out of the addComponent / addComponents call — the component never sees onAdded. This is the engine's atomic-add contract.

Parameters

Returns

TDeps
ESC