Skip to main content

Function: addCanvasComponent()

addCanvasComponent(world, entity, options): CanvasEcsComponent

Defined in: ui/components/canvas-component.ts:165

Attaches a CanvasEcsComponent to entity. A canvas also needs a RectTransformEcsComponent and a PositionEcsComponent - for renderMode: 'screenSpace' (the default), the rect is resolved every frame from referenceResolution/scaleMode rather than a parent; for 'worldSpace', it's an ordinary rect positioned via the entity hierarchy like any other UI element. Use createUiCanvas to get a fully wired canvas entity - including its camera for 'screenSpace' mode - in one call.

Parameters​

world​

EcsWorld

The ECS world entity belongs to.

entity​

number

The entity to attach the component to.

options​

AddCanvasComponentOptions

Options for configuring the canvas. camera has no sensible default and must always be provided; which of the other fields are available depends on renderMode (see ScreenSpaceCanvasFields / WorldSpaceCanvasFields).

Returns​

CanvasEcsComponent

The attached component, for further tuning or runtime changes.