arcade2d
Interface

WorldObjectComponent

world/dependencies.types.ts:252

Extends Component<WorldObject, TDeps>

A component attached to a WorldObject. Use this rather than the lower-level Component interface for any per-object behaviour — controllers, graphics, colliders, audio sources, gameplay logic — both because the name reads better in docs/imports and because the dependency resolver also exposes cross-tier lookups against the parent World via requireFromWorld / optionalFromWorld.

Declaring dependencies on world-scoped infrastructure

The canonical use case for object-component dependencies is "I need to talk to a world-scoped system." A graphics component needs the renderer. A physics body needs the simulation. An audio source needs the mixer.

type GraphicsDeps = { renderer: RendererSystem };

class GraphicsComponent implements WorldObjectComponent<GraphicsDeps> {
  constructor(public readonly host: WorldObject) {}

  resolveDependencies(
    resolver: WorldObjectDependencyResolver,
  ): GraphicsDeps {
    return { renderer: resolver.requireFromWorld(RendererSystem) };
  }

  onAdded({ renderer }: GraphicsDeps): void {
    renderer.register(this);
  }

  onDestroy({ renderer }: GraphicsDeps): void {
    renderer.unregister(this);
  }
}

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: WorldObject

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: WorldObjectDependencyResolver): TDeps

Optional dependency declaration. See WorldComponent.resolveDependencies for the lifecycle contract.

Parameters

Returns

TDeps
ESC