onPresentation07 / 7

Updating the camera, world and UI

Apply changes after physics and animation.

If a camera updates before an object moves, it can lag by one frame. The SDK runs onPresentation after physics and tweens, before rendering. Set the order of related changes to camera → world → ui.

In a Three node component, register a presentation update in onReady:

import { BaseComponent } from '@gamedevland/engine/layouts';
import { ThreeNode } from '@gamedevland/engine/renderers/three';

export class FollowPositionComponent extends BaseComponent<ThreeNode> {
  protected readonly nodeType = ThreeNode;

  protected override onReady(): void {
    const target = this.node.engine.getRequiredActiveLayout().requireNode('world.target', ThreeNode);
    this.onPresentation(() => {
      this.node.setPosition(target.view.position);
    }, { phase: 'world' });
  }
}

Both nodes are in the same group here: we copy the local position of world.target. Use the camera phase for the camera and ui for labels over the world.

cameraUpdate the camera
worldApply object presentation
uiUpdate the interface
The SDK then renders the frame.

The subscription is scoped to the layout and component lifetime: it does not run while the component is disabled and is removed on detach. Within a phase, order sets numeric ordering. The callback is synchronous; the engine does not await a returned Promise.

Course curriculum →