Skip to main content

Function: createUiLayoutEcsSystem()

createUiLayoutEcsSystem(renderContext): EcsSystem<[RectTransformDefaultedOptions, PositionEcsComponent]>

Defined in: ui/systems/ui-layout-system.ts:206

Creates a system that resolves every RectTransformEcsComponent against its parent's rect, top-down, in hierarchy pre-order starting from each CanvasEcsComponent's root. For each element it writes the resolved RectTransformEcsComponent.rect, the entity's PositionEcsComponent.local (so the existing createTransformEcsSystem composes the correct position.world), and RectTransformEcsComponent.sortDepth - and, for elements that also carry a SpriteEcsComponent and/or a TextEcsComponent, their sortDepth too (plus, for a sprite, its width/height/pivot) - all set to the element's hierarchy pre-order index, so draw order follows hierarchy order within a canvas regardless of whether a panel and its label happen to share a world Y (draw order otherwise ties on position.world.y, which a panel and a centered child label routinely don't share), and createUiRaycastEcsSystem has a topmost-first ordering for every interactable regardless of whether it happens to draw anything.

A renderMode: 'screenSpace' canvas root's rect (and its camera's verticalWorldUnits) is recomputed from renderContext's current dimensions every call, so resizing the render destination is picked up automatically on the next frame with no separate resize hook - this system does a full recompute every frame rather than tracking dirty state, favoring correctness over the added complexity dirty-tracking a retained tree would need. Its camera's renderTarget, if it has one (see createUiCanvas), is resized to match renderContext the same way, so the UI's own off-screen target never drifts out of sync with the destination it's composited onto.

A renderMode: 'worldSpace' canvas root is resolved exactly like any other element instead - against its own parent's rect (or, with no UI parent, as an ordinary root) - and its camera is never touched, since a world-space canvas typically shares the game's own world camera.

Also computes each canvas's current reference-pixel-to-screen-pixel ratio (calculatePixelsPerUnit(renderContext.height, verticalWorldUnits), re-derived from whichever camera that canvas root just resolved) and threads it down through the whole subtree, so any descendant's 'screenPixels'-unit UiAxis size/margin (see UiAxisSizeUnit) converts against the ratio that's actually live for the canvas it belongs to, not a stale or unrelated one.

Must be registered before createTransformEcsSystem.

Parameters​

renderContext​

RenderContext

The render context UI canvases resolve their root rect against.

Returns​

EcsSystem<[RectTransformDefaultedOptions, PositionEcsComponent]>

The UI layout ECS system.