Skip to main content

Editor.Components.Canvas

Class

Manages 2D canvas rendering and layout properties for a scene object.

Index

Example

const model = this.pluginSystem.findInterface(Editor.Model.IModel) as Editor.Model.IModel;
const scene = model.project.scene;

// Canvas is the root for ScreenTransform-based UI layouts. It's most
// commonly used for 2D HUD/UI, but it also works in 3D space — drop it
// on any SceneObject and its children with ScreenTransform render in
// local 2D coordinates. SortingType.Hierarchy draws children in scene
// tree order, which is handy for stacked panels placed in 3D.
// See: https://developers.snap.com/lens-studio/lens-studio-workflow/scene-set-up/2d/canvas-component
const obj = scene.createSceneObject('UICanvas');
const canvas = obj.addComponent('Canvas') as Editor.Components.Canvas;

canvas.unitType = Editor.Components.UnitType.Pixels;
canvas.sortingType = Editor.Components.SortingType.Hierarchy;
canvas.pivot = new vec2(0.5, 0.5);
console.log(`Canvas: unitType=${canvas.unitType}, sorting=${canvas.sortingType}`);

Extends

Properties

debugRenderLayoutRect

debugRenderLayoutRect: boolean

If enabled, draws the Canvas.layoutRect bounds as a wireframe for debugging Canvas layout.


enabled

enabled: boolean

Whether the component is active.

Inherited from

Component.enabled


hasPrefabChanges

readonly hasPrefabChanges: boolean

Whether this entity differs from its counterpart in the prefab or was added to the prefab instance. Always false outside prefab instances.

Inherited from

Component.hasPrefabChanges


id

readonly id: Uuid

The unique id of the entity.

Inherited from

Component.id


isPrefabInstanceRoot

readonly isPrefabInstanceRoot: boolean

Whether this entity is the root of a prefab instance.

Inherited from

Component.isPrefabInstanceRoot


layoutRect

layoutRect: Rect

The rectangular bounds that define the area child objects are laid out within. Each bound is defined as an offset in world units from the SceneObject's position.


meta

readonly meta: Meta

Metadata associated with this entity, providing access to its unique identifier and other descriptive properties.

Inherited from

Component.meta


name

name: string

Name of the component.

Inherited from

Component.name


pivot

pivot: vec2

Anchor point for the canvas as a normalized 2D vector.


sceneObject

readonly sceneObject: SceneObject

Scene object this component is attached to.

Inherited from

Component.sceneObject


sortingType

sortingType: SortingType

Determines how the canvas sorts its children during rendering.


type

readonly type: string

The entity's type.

Inherited from

Component.type


unitType

unitType: UnitType

Specifies the unit system used for canvas measurements.

Methods

getDirectlyReferencedEntities()

getDirectlyReferencedEntities(): Entity[]

A list of entities which this entity has a reference to.

Returns

Entity[]

Inherited from

Component.getDirectlyReferencedEntities


getMeta()

static getMeta(): Meta

Returns metadata about this type.

Returns

Meta

Overrides

Component.getMeta


getOwnedEntities()

getOwnedEntities(): Entity[]

A list of entities which has a reference to this entity.

Returns

Entity[]

Inherited from

Component.getOwnedEntities


getPrefabInstanceRoot()

getPrefabInstanceRoot(): Prefabable

Returns the nearest prefab instance root that contains this entity, starting with the entity itself, or null if it is not part of a prefab instance.

Returns

Prefabable

Inherited from

Component.getPrefabInstanceRoot


getTypeName()

static getTypeName(): string

Returns the type name of this class.

Returns

string

Overrides

Component.getTypeName


getTypeName()

getTypeName(): string

Returns the name of this object's type.

Returns

string

Inherited from

Component.getTypeName


isOfType()

isOfType(type): boolean

Returns true if the object is of the specified type.

Parameters

ParameterType
typestring

Returns

boolean

Inherited from

Component.isOfType


isSame()

isSame(other): boolean

Returns true if this object refers to the same instance as the given object.

Parameters

ParameterType
otherScriptObject

Returns

boolean

Inherited from

Component.isSame