Skip to main content

Function: createLabel()

createLabel(world, parent, options): number

Defined in: ui/utilities/create-label.ts:67

Creates a UI label: an entity with a RectTransformEcsComponent (parented to parent) and a TextEcsComponent. Every TextEcsComponent option (text, fontAtlas, size, and the rest) is accepted directly. category is not defaulted here - omitted, it falls through to TextEcsComponent's own default (TEXT_RENDER_CATEGORY), which has nothing to do with any particular canvas's culling mask. To make a label visible through a specific createUiCanvas, pass the same category value you gave that canvas's cullingMask (see ScreenSpaceUiCanvasOptions.cullingMask for why there's no shared default to fall back on).

Parameters​

world​

EcsWorld

The ECS world to create the label entity in.

parent​

number

The entity to parent the label to - required, no default. There's no standalone "no parent" case: pass the canvas entity itself (see createUiCanvas) for a top-level label, or another UI element (a panel, a button) to position the label relative to it, the way createButton parents its own label to the button rather than to the canvas directly.

options​

CreateLabelOptions

Options for configuring the label. text, fontAtlas, and size have no sensible default and must always be provided.

Returns​

number

The created label entity.