Contents

PlayCanvas Editor API: All Pages

The API reference of @playcanvas/editor-api 1.1.28: the classes and types for automating and extending the PlayCanvas Editor from its browser console or user scripts. The API is in beta.

The same pages as Markdown, for AI agents: llms-full.txt.

Contents

Asset

Class · extends Events · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/asset.ts#L25

The Asset class represents an asset in Editor.

Constructors

constructor

new Asset(data?: any)

Constructor

Parameters

Accessors

history

get history(): ObserverHistory

Gets observer history for this asset.

observer

get observer(): AssetObserver

The observer object for this asset.

Methods

delete

delete(): Promise<void>

Deletes this asset.

Returns Promise<void>

get

get(path: string): any

Gets value at path. See the Asset overview for a full list of properties.

Parameters

Returns any: The value

has

has(path: string): boolean

Checks if path exists. See the Asset overview for a full list of properties.

Parameters

Returns boolean: True if path exists

insert

insert(path: any, value: any, index: any): boolean

Inserts value in array at path, at specified index. See the Asset overview for a full list of properties.

Parameters

Returns boolean: Whether the value was inserted

instantiateTemplate

instantiateTemplate(parent: Entity, options?: object): Promise<Entity>

Creates an instance of this template asset. Assumes this asset is a template asset.

Parameters

Returns Promise<Entity>: The new entity.

json

json(): Record<string, any>

Returns JSON representation of entity data

Returns Record<string, any>: - The data

latest

latest(): Asset

Returns the latest version of the Asset from the Assets API.

Returns Asset: The asset

load

load(): Promise<void>

Loads asset from the server without subscribing to realtime changes.

Returns Promise<void>

loadAndSubscribe

loadAndSubscribe(): Promise<void>

Loads the asset's data from sharedb and subscribes to changes.

Returns Promise<void>

removeValue

removeValue(path: any, value: any): boolean

Remove value from array at path. See the Asset overview for a full list of properties.

Parameters

Returns boolean: Whether the value was removed

replace

replace(asset: Asset, options?: object): void

Replaces any references to this asset with references to the new asset specified.

Parameters

set

set(path: string, value: any): boolean

Sets value at path. See the Asset overview for a full list of properties.

Parameters

Returns boolean: Whether the value was set

unset

unset(path: string): boolean

Unsets value at path. See the Asset overview for a full list of properties.

Parameters

Returns boolean: Whether the value was unset

getFileUrl

static getFileUrl(id: number, filename: string): string

Gets the file URL for an asset file.

Parameters

Returns string: The file URL

Assets

Class · extends Events · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/assets.ts#L148

The Assets Editor API

Constructors

constructor

new Assets(options?: object)

Constructor

Parameters

Accessors

defaultUploadCompletedCallback

get defaultUploadCompletedCallback(): (uploadId: number, asset: Asset) => any
set defaultUploadCompletedCallback(value: (uploadId: number, asset: Asset) => any)

Gets the default callback called when on asset upload succeeds.

defaultUploadErrorCallback

get defaultUploadErrorCallback(): (uploadId: number, error: Error) => any
set defaultUploadErrorCallback(value: (uploadId: number, error: Error) => any)

Gets the default callback called when on asset upload fails.

defaultUploadProgressCallback

get defaultUploadProgressCallback(): (uploadId: number, progress: number) => any
set defaultUploadProgressCallback(value: (uploadId: number, progress: number) => any)

Gets the default callback called when on asset upload progress.

parseScriptCallback

get parseScriptCallback(): (asset: Asset) => any
set parseScriptCallback(value: (asset: Asset) => any)

Gets the callback which parses script assets.

Methods

add

add(asset: Asset): void

Adds asset to the list

Parameters

clear

clear(): void

Removes all assets from the list

createAnimStateGraph

createAnimStateGraph(options?: object): Promise<Asset>

Creates new anim state graph asset.

Parameters

Returns Promise<Asset>: The new asset

createBundle

createBundle(options?: object): Promise<Asset>

Creates new bundle asset

Parameters

Returns Promise<Asset>: The new asset

createCss

createCss(options?: object): Promise<Asset>

Creates new CSS asset

Parameters

Returns Promise<Asset>: The new asset

createCubemap

createCubemap(options?: object): Promise<Asset>

Creates new cubemap asset

Parameters

Returns Promise<Asset>: The new asset

createFolder

createFolder(options: object): Promise<Asset>

Creates a new folder asset

Parameters

Returns Promise<Asset>: The new asset

createHtml

createHtml(options?: object): Promise<Asset>

Creates new HTML asset

Parameters

Returns Promise<Asset>: The new asset

createI18n

createI18n(options?: object): Promise<Asset>

Creates new localization JSON asset

Parameters

Returns Promise<Asset>: The new asset

createJson

createJson(options?: object): Promise<Asset>

Creates new JSON asset

Parameters

Returns Promise<Asset>: The new asset

createMaterial

createMaterial(options?: object): Promise<Asset>

Creates new material asset

Parameters

Returns Promise<Asset>: The new asset

createScript

createScript(options?: object): Promise<Asset>

Creates new script asset

Parameters

Returns Promise<Asset>: The new asset

createShader

createShader(options?: object): Promise<Asset>

Creates new shader asset

Parameters

Returns Promise<Asset>: The new asset

createSprite

createSprite(options?: object): Promise<Asset>

Creates new sprite asset

Parameters

Returns Promise<Asset>: The new asset

createTemplate

createTemplate(options: object): Promise<void>

Creates new template asset

Parameters

Returns Promise<void>: The new asset

createText

createText(options?: object): Promise<Asset>

Creates new text asset

Parameters

Returns Promise<Asset>: The new asset

delete

delete(assets: Asset[]): Promise<void>

Deletes specified assets

Parameters

Returns Promise<void>

filter

filter(fn: Function): any[]

Gets assets that satisfy function

Parameters

Returns any[]: The assets

findOne

findOne(fn: Function): any

Finds first asset that satisfies function

Parameters

Returns any: The asset

get

get(id: number): Asset

Gets asset by id

Parameters

Returns Asset: The asset

getAssetForScript

getAssetForScript(script: string): any

Gets the first script asset that contains the specified script

Parameters

Returns any: The script asset

getUnique

getUnique(uniqueId: number): Asset

Gets asset by its unique id

Parameters

Returns Asset: The asset

instantiateTemplates

instantiateTemplates(assets: Asset[], parent: Entity, options?: object): Promise<Entity[]>

Instantiates the specified template assets under the specified parent entity.

Parameters

Returns Promise<Entity[]>: The new entities

list

list(): Asset[]

Returns array of all assets

Returns Asset[]: The assets

listByTag

listByTag(...tags: any[]): any[]

Finds all assets with specified tags

Parameters

Returns any[]: The assets

loadAll

loadAll(options?: object): Promise<void>

Loads all assets in the current project / branch. Does not subscribe to realtime changes.

Parameters

Returns Promise<void>

loadAllAndSubscribe

loadAllAndSubscribe(options?: object): Promise<void>

Loads all assets in the current project / branch and subscribes to changes.

Parameters

Returns Promise<void>

remove

remove(asset: Asset): void

Removes asset from the list

Parameters

upload

upload(data: AssetUploadArguments, settings?: TextureImportSettings | SceneImportSettings, onProgress?: Function): Promise<Asset>

Creates new asset

Parameters

Returns Promise<Asset>: The new asset

AssetsSchema

Class · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/schema/assets.ts#L7

Provides methods to access the Assets schema

Constructors

constructor

new AssetsSchema(schema: Schema)

Parameters

Methods

getDefaultData

getDefaultData(type: string): Record<string, any>

Gets default data for asset type

Parameters

Returns Record<string, any>: The default data

getFieldsOfType

getFieldsOfType(assetType: string, type: string): string[]

Gets a list of fields of a particular type for an asset type

Parameters

Returns string[]: A list of fields

Example

const materialAssetPaths = editor.schema.assets.getFieldsOfType('material', 'asset');

ComponentSchema

Class · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/schema/components.ts#L7

Provides methods to access the components schema

Constructors

constructor

new ComponentSchema(schema: Schema)

Creates new instance of API

Parameters

Methods

getDefaultData

getDefaultData(component: string): Record<string, any>

Gets default data for a component

Parameters

Returns Record<string, any>: The default data

Example

const modelData = editor.schema.components.getDefaultData('model');

getFieldsOfType

getFieldsOfType(componentName: string, type: string): string[]

Gets a list of fields of a particular type for a component

Parameters

Returns string[]: A list of fields

Example

const buttonEntityFields = editor.schema.components.getFieldsOfType('button', 'entity');

list

list(): string[]

Gets a list of all the available components

Returns string[]: The components

Entities

Class · extends Events · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/entities.ts#L93

The entities editor API

Constructors

constructor

new Entities()

Creates new API instance

Accessors

root

get root(): Entity

Gets the root Entity

Methods

add

add(entity: Entity): void

Adds entity to list

Parameters

addScript

addScript(entities: Entity[], scriptName: string, options?: object): Promise<void>

Like Entity.addScript but works on multiple entities using a single history action.

Parameters

Returns Promise<void>: A promise

clear

clear(): void

Removes all entities from the list

copyToClipboard

copyToClipboard(entities: Entity[]): void

Copy specified entities to localStorage clipboard. Can be used to paste these entities later on.

Parameters

create

create(data?: CreateEntityArguments, options?: object): Entity

Creates new entity and adds it to the hierarchy

Parameters

Returns Entity: The new entity

Example

const root = editor.entities.create({
    name: 'parent',
});

const child = editor.entities.create({
    name: 'child',
    parent: root,
});

delete

delete(entities: Entity | Entity[], options?: object): Promise<void>

Delete specified entities

Parameters

Returns Promise<void>

Example

await editor.entities.delete([entity1, entity2]);

duplicate

duplicate(entities: Entity[], options?: object): Promise<Entity[]>

Duplicates the specified entities under the same parent

Parameters

Returns Promise<Entity[]>: The duplicated entities

Example

const duplicated = await editor.entities.duplicate(entities);

get

get(id: string): Entity

Gets entity by resource id

Parameters

Returns Entity: The entity

Example

const entity = editor.entities.get(resourceId);

list

list(): any[]

Returns array of all entities

Returns any[]: The entities

Example

const entities = editor.entities.list();
console.log(entities.length);

pasteFromClipboard

pasteFromClipboard(parent: Entity, options?: object): Promise<Entity[]>

Paste entities copied into clipboard under the specified parent.

Parameters

Returns Promise<Entity[]>: The new entities

remove

remove(entity: Entity, entityReferences?: object): void

Removes entity from the list

Parameters

removeScript

removeScript(entities: Entity[], scriptName: string, options?: object): void

Like Entity.removeScript but works on multiple entities using a single history action.

Parameters

reparent

reparent(data: ReparentArguments[], options?: object): void

Reparents entities under new parent.

Parameters

Example

const child = editor.entities.create();
const parent = editor.entities.create();
editor.entities.reparent([{
    entity: child,
    parent: parent
}])

serverAdd

serverAdd(entityData: object): void

Called when an entity is added from the server

Parameters

serverRemove

serverRemove(entity: Entity): void

Called when an entity is removed from the server

Parameters

waitToExist

waitToExist(entityIds: string[], timeoutMs: number, callback: (entities: Entity[]) => void): () => void

Waits for specified entity ids to be added to the scene. Once they are the callback is called with the entities as its argument.

Parameters

Returns () => void: Returns a cancel function which can be called to cancel calling the callback when the entities are added.

Entity

Class · extends Events · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/entity.ts#L34

The Entity class represents an entity in the Editor.

Constructors

constructor

new Entity(data?: any)

Creates new Entity

Parameters

Accessors

children

get children(): Entity[]

The children entities. Warning: this creates a new array every time it's called.

history

get history(): ObserverHistory

The history object for this entity.

observer

get observer(): EntityObserver

The observer object for this entity.

parent

get parent(): Entity

The parent entity.

viewportEntity

get viewportEntity(): any

The entity in the 3D viewport of the Editor.

Methods

addChild

addChild(entity: Entity): boolean

Adds entity as a child

Parameters

Returns boolean: Whether the child was added

addComponent

addComponent(component: string, data?: {}): void

Adds a component to this Entity

Parameters

Example

editor.entities.root.addComponent('model', {
    type: 'box'
});

addScript

addScript(scriptName: string, options?: object): Promise<void>

Adds a script to the script component of this entity. If a script component does not exist, this method will add the script component as well.

Parameters

Returns Promise<void>: A promise

delete

delete(options?: object): Promise<void>

Deletes entity (and its children)

Parameters

Returns Promise<void>: A promise

Example

editor.entities.root.findByName('door').delete();

depthFirst

depthFirst(fn: (entity: Entity) => void): void

Executes function for this entity and its children in depth first order.

Parameters

Example

// get a list of all entities in the graph in depth first order
const entities = [];
editor.entities.root.depthFirst(entity => entities.push(entity));

duplicate

duplicate(options?: object): Promise<Entity>

Duplicates entity under the same parent

Parameters

Returns Promise<Entity>: The new entity

filter

filter(fn: (entity: Entity) => boolean): Entity[]

Returns the entity and children that satisfy the function

Parameters

Returns Entity[]: The result

Example

const doors = editor.entities.root.filter(entity => entity.get('name').startsWith('door'));

findByName

findByName(name: string): Entity

Finds first entity by name using depth-first search

Parameters

Returns Entity: The entity

Example

const door = editor.entities.root.findByName('Door');

get

get(path: string): any

Gets value at path. See Entity for a list of properties.

Parameters

Returns any: The value

Example

console.log(entity.get('position'));

has

has(path: string): boolean

Checks if path exists. See Entity for a list of properties.

Parameters

Returns boolean: True if path exists

Example

console.log(entity.has('components.model'));

insert

insert(path: string, value: any, index?: number): boolean

Inserts value in array at path, at specified index. See Entity for a list of properties.

Parameters

Returns boolean: Whether the value was inserted

Example

entity.insert('tags', 'a_tag');

insertChild

insertChild(entity: Entity, index?: number): boolean

Inserts entity as a child at specified index.

Parameters

Returns boolean: Whether the child was added

isDescendantOf

isDescendantOf(parent: Entity): boolean

Returns true if this entity is a descendant of the specified parent entity.

Parameters

Returns boolean: True if it is

json

json(): Record<string, any>

Returns JSON representation of entity data

Returns Record<string, any>: - The data

console.log(entity.json());

jsonHierarchy

jsonHierarchy(): any

Returns a JSON representation of entity data. The children array of the entity gets recursively converted to an array of entity data instead of containing children resource ids.

Returns any: - The data

Example

const data = entity.jsonHierarchy();
console.log(data.children[0].name);

latest

latest(): Entity

Returns the latest version of the Entity from the Entities API.

Returns Entity: The entity

listByTag

listByTag(...tags: any[]): Entity[]

Finds all entities with specified tags

Parameters

Returns Entity[]: The entities

Example

// entities that have the following tag
const entities = editor.entities.root.listByTag('tag');
// entities that have any of the following tags
const entities = editor.entities.root.listByTag('tag', 'tag2');
// entities that have all of the following tags
const entities = editor.entities.root.listByTag(['tag', 'tag2']);

removeChild

removeChild(entity: Entity): void

Removes entity from children

Parameters

removeComponent

removeComponent(component: string): void

Removes a component from this Entity

Parameters

Example

editor.entities.root.removeComponent('model');

removeScript

removeScript(scriptName: string, options?: object): void

Removes a script from the entity's script component.

Parameters

removeValue

removeValue(path: string, value: any): boolean

Remove value from array at path. See Entity for a list of properties.

Parameters

Returns boolean: Whether the value was removed

Example

entity.removeValue('tags', 'a_tag');

reparent

reparent(parent: Entity, index?: number, options?: object): void

Reparents entity under new parent

Parameters

Example

const redHouse = editor.entities.root.findByName('red house');
const greenHouse = editor.entities.root.findByName('green house');
const door = redHouse.findByName('door');
door.reparent(greenHouse);

set

set(path: string, value: any): boolean

Sets value at path. See Entity for a list of properties.

Parameters

Returns boolean: Whether the value was set

Example

entity.set('position', [1, 0, 0]);

unset

unset(path: string): boolean

Unsets value at path. See Entity for a list of properties.

Parameters

Returns boolean: Whether the value was unset

Example

entity.unset('components.model');

globals

Class · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/globals.ts#L16

Global variables

Properties

accessToken

static accessToken: string

The user's access token

apiUrl

static apiUrl: string = ''

The REST API URL

assets

static assets: Assets

The assets API

branchId

static branchId: string

The current branch id

clipboard

static clipboard: Clipboard

The main clipboard

entities

static entities: Entities

The entities API

hasLegacyScripts

static hasLegacyScripts: boolean

Whether this project is using legacy scripts

history

static history: History

The history API

homeUrl

static homeUrl: string = ''

The home URL

jobs

static jobs: Jobs

The jobs API

messenger

static messenger: Messenger

The messenger API

projectId

static projectId: number

The current project id

realtime

static realtime: Realtime

The realtime API

schema

static schema: Schema

The schema API

selection

static selection: Selection

The selection API

settings

static settings: Settings

The settings API

Methods

confirmFn

static confirmFn(text: string, options?: object): Promise<boolean>

Alert function called when user confirmation is needed for an action. Defaults to the default browser popup but can be overridden to show your custom popup instead.

Parameters

Returns Promise<boolean>: True if the user confirmed, false otherwise

History

Class · extends Events · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/history.ts#L7

The history API responsible for undo / redo.

Constructors

constructor

new History()

Creates new instance of the API

Accessors

canRedo

get canRedo(): boolean
set canRedo(value: boolean)

Gets whether there are actions to redo.

canUndo

get canUndo(): boolean
set canUndo(value: boolean)

Gets whether there are actions to undo.

currentAction

get currentAction(): HistoryAction

Gets the current action

lastAction

get lastAction(): HistoryAction

Gets the last action

Methods

add

add(action: HistoryAction): void

Adds history action

Parameters

Example

const prevSelection = editor.selection.items;
editor.history.add({
    name: 'clear selection',
    redo: () => { editor.selection.clear({ history: false }); },
    undo: () => { editor.selection.set(prevSelection, { history: false }); },
});

addAndExecute

addAndExecute(action: HistoryAction): void

Adds history action and execute redo

Parameters

Example

const prevSelection = editor.selection.items;
editor.history.addAndExecute({
    name: 'clear selection',
    redo: () => { editor.selection.clear({ history: false }); },
    undo: () => { editor.selection.set(prevSelection, { history: false }); },
});

clear

clear(): void

Clear history

Example

editor.history.clear();

redo

redo(): void

Redo last action

Example

editor.history.redo();

undo

undo(): void

Undo last action

Example

editor.history.undo();

SceneSchema

Class · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/schema/scene.ts#L7

Provides methods to access the render schema

Constructors

constructor

new SceneSchema(schema: Schema)

Creates new instance of API

Parameters

Methods

getDefaultPhysicsSettings

getDefaultPhysicsSettings(): Record<string, any>

Get the default physics scene settings for the project

Returns Record<string, any>: The default physics scene settings

Example

const scenePhysicsSettings = editor.schema.scene.getDefaultPhysicsSettings();

getDefaultRenderSettings

getDefaultRenderSettings(): Record<string, any>

Get the default render scene settings for the project

Returns Record<string, any>: The default physics scene settings

Example

const sceneRenderSettings = editor.schema.scene.getDefaultRenderSettings();

SceneSettings

Class · extends Events · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/settings/scene.ts#L14

The Scene Settings API provides access to the settings of the currently loaded scene.

Constructors

constructor

new SceneSettings()

Creates new instance of the API

Accessors

history

get history(): ObserverHistory

Gets the history object for this entity

Methods

get

get(path: string): any

Gets value at path. See the SceneSettings overview for a full list of properties.

Parameters

Returns any: The value

Example

console.log(editor.settings.scene.get('render.fog'));

has

has(path: string): boolean

Checks if path exists. See the SceneSettings overview for a full list of properties.

Parameters

Returns boolean: True if path exists

Example

console.log(editor.settings.scene.has('render.fog'));

json

json(): Record<string, any>

Returns JSON representation of scene settings data

Returns Record<string, any>: - The data

Example

console.log(editor.settings.scene.json());

set

set(path: string, value: any): boolean

Sets value at path. See the SceneSettings overview for a full list of properties.

Parameters

Returns boolean: Whether the value was set

Example

editor.settings.scene.set('render.fog', 'none');

Schema

Class · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/schema.ts#L9

Provides methods to access the Editor schema.

Constructors

constructor

new Schema(schema: any)

Creates new instance of API

Parameters

Accessors

assets

get assets(): AssetsSchema

Gets the assets schema

components

get components(): ComponentSchema

Gets the component schema

scene

get scene(): SceneSchema

Gets the scene schema

schema

get schema(): any

Gets the schema

settings

get settings(): SettingsSchema

Gets the settings schema

Methods

getType

getType(field: any, fixedLength?: number): string

Converts the specified schema field to a type recursively.

Parameters

Returns string

Selection

Class · extends Events · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/selection.ts#L80

Selection API. Allows selecting Entities, Assets etc.

Constructors

constructor

new Selection()

Constructor

Accessors

count

get count(): number

Gets the number of selected items

enabled

get enabled(): boolean
set enabled(value: boolean)

Gets enabled state of the selection methods.

history

get history(): SelectionHistory

Gets the selection history

item

get item(): Entity | Asset

Gets the first selected item. Short for this.items[0].

items

get items(): (Entity | Asset)[]

Gets the selected items. This creates a new array every time it is called.

Example

editor.selection.items.add(editor.entities.root);
const selectedEntities = editor.selection.items;

Methods

add

add(item: any, options?: object): void

Add item to selection

Parameters

Example

// add root entity to selection
editor.selection.add(editor.entities.root);

clear

clear(options?: object): void

Clears selection

Parameters

Example

editor.selection.clear();

has

has(item: any): boolean

Checks if item is in selection

Parameters

Returns boolean

Example

const isRootSelected = editor.selection.has(editor.entities.root);

remove

remove(item: any, options?: object): void

Remove item from selection

Parameters

Example

// remove root entity from selection
editor.selection.remove(editor.entities.root);

set

set(items: any[], options?: object): void

Sets current selection

Parameters

Example

// select root entity
editor.selection.set([editor.entities.root]);

toggle

toggle(item: any, options?: object): void

Toggle item selection

Parameters

Example

// toggle root entity selection
editor.selection.toggle(editor.entities.root);

SelectionHistory

Class · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/selection.ts#L10

Enables undo / redo of selection changes

Constructors

constructor

new SelectionHistory(selection: Selection)

Constructor

Parameters

Accessors

enabled

get enabled(): boolean
set enabled(value: boolean)

Gets enabled state of selection undo / redo.

Methods

wrapAction

wrapAction(name: any, fn: () => void): void

Record history action after executing function. The history action will restore the previous selection.

Parameters

Settings

Class · extends Events · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/settings.ts#L8

The settings for the Editor.

Constructors

constructor

new Settings()

Creates new API instance

Accessors

scene

get scene(): SceneSettings

Gets the settings for the currently loaded scene.

SettingsSchema

Class · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/schema/settings.ts#L7

Provides methods to access the settings schema

Constructors

constructor

new SettingsSchema(schema: Schema)

Creates new instance of API

Parameters

Methods

getDefaultProjectSettings

getDefaultProjectSettings(): Record<string, any>

Get the default settings for the project

Returns Record<string, any>: The default settings for the project

Example

const projectSettings = editor.schema.settings.getDefaultProjectSettings();

getDefaultProjectUserSettings

getDefaultProjectUserSettings(): Record<string, any>

Get the default settings for the user in the project

Returns Record<string, any>: The default settings for the user in the project

Example

const projectUserSettings = editor.schema.settings.getDefaultProjectUserSettings();

getDefaultUserSettings

getDefaultUserSettings(): Record<string, any>

Get the default settings for the user

Returns Record<string, any>: The default settings for the user

Example

const userSettings = editor.schema.settings.getDefaultUserSettings();

AnimationAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L128

Represents the data for an Animation asset.

type AnimationAssetData = undefined

AnimationComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L158

Animation Component Properties.

type AnimationComponent = undefined

AnimComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L94

Anim Component Properties.

type AnimComponent = undefined

AnimstategraphAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L160

Represents the data for an AnimStateGraph asset.

type AnimstategraphAssetData = undefined

AssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L111

Represents the data for an Asset.

type AssetData = AnimationAssetData | AnimstategraphAssetData | BundleAssetData | CubemapAssetData | FontAssetData | MaterialAssetData | ModelAssetData | RenderAssetData | ScriptAssetData | SpriteAssetData | TextureAssetData | TextureAtlasAssetData | WasmAssetData

AssetObserver

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/asset.ts#L10

Represents an observer for an asset, extending the base Observer.

type AssetObserver = Observer & { apiAsset: Asset; history: ObserverHistory }

AssetProps

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L6

Represents an Asset.

What follows is a reference for all possible asset paths that can be passed to functions such as Asset#get and Asset#set.

type AssetProps = undefined

AssetUploadArguments

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/assets.ts#L13

Arguments passed when uploading an asset file.

type AssetUploadArguments = undefined

AudioListenerComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L189

AudioListener Component Properties.

type AudioListenerComponent = undefined

BundleAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L319

Represents the data for a Bundle asset.

type BundleAssetData = undefined

ButtonComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L200

Button Component Properties.

type ButtonComponent = undefined

CameraComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L281

Camera Component Properties.

type CameraComponent = undefined

CollisionComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L352

Collision Component Properties.

type CollisionComponent = undefined

Components

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L68

Components of an Entity.

type Components = undefined

CreateEntityArguments

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/entities.ts#L18

Data to create a new Entity

type CreateEntityArguments = undefined

CubemapAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L329

Represents the data for a Cubemap asset.

type CubemapAssetData = undefined

ElementComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L398

Element Component Properties.

type ElementComponent = undefined

EntityObserver

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/entity.ts#L9

Represents an observer for an entity, extending the base Observer.

type EntityObserver = Observer & { apiEntity: Entity; entity: any; history: ObserverHistory; latestFn: () => Observer }

EntityProps

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L8

Represents an Entity.

What follows is a reference for all possible asset paths that can be passed to functions such as Entity#get and Entity#set.

Common Entity Properties:

type EntityProps = undefined

FontAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L357

Represents the data for a Font asset.

type FontAssetData = undefined

LayoutChildComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L599

LayoutChild Component Properties.

type LayoutChildComponent = undefined

LayoutGroupComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L645

LayoutGroup Component Properties.

type LayoutGroupComponent = undefined

LightComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L701

Light Component Properties.

type LightComponent = undefined

MaterialAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L445

Represents the data for a Material asset.

type MaterialAssetData = undefined

MessagerClient

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/messenger.ts#L9

The MessagerClient interface extends the Events class and defines the methods and properties required for the Messenger client.

type MessagerClient = Events & { isConnected: boolean; authenticate: any; connect: any; projectWatch: any }

ModelAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L935

Represents the data for a Model asset.

type ModelAssetData = undefined

ModelComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L831

Model Component Properties.

type ModelComponent = undefined

ParticleSystemComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L909

ParticleSystem Component Properties.

type ParticleSystemComponent = undefined

RenderAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L950

Represents the data for a Render asset.

type RenderAssetData = undefined

RenderComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1120

Render Component Properties.

type RenderComponent = undefined

ReparentArguments

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/entities.ts#L73

Data to reparent an entity under a new parent

type ReparentArguments = undefined

RigidBodyComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1199

RigidBody Component Properties.

type RigidBodyComponent = undefined

SceneImportSettings

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/assets.ts#L88

Import settings used when uploading a scene (fbx etc.).

type SceneImportSettings = undefined

SceneSettingsObserver

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/settings/scene.ts#L9

Represents an observer for the Scene Settings, extending the base Observer.

type SceneSettingsObserver = Observer & { history: ObserverHistory }

SceneSettingsProps

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/scene-settings.d.ts#L4

Represents the settings for the currently loaded scene.

type SceneSettingsProps = undefined

ScreenComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1250

Screen Component Properties.

type ScreenComponent = undefined

ScriptAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L964

Represents the data for a Script asset.

type ScriptAssetData = undefined

ScriptComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1286

Script Component Properties.

type ScriptComponent = undefined

ScrollbarComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1319

Scrollbar Component Properties.

type ScrollbarComponent = undefined

ScrollviewComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1350

Scrollview Component Properties.

type ScrollviewComponent = undefined

SoundComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1426

Sound Component Properties.

type SoundComponent = undefined

SpriteAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L1070

Represents the data for a Sprite asset.

type SpriteAssetData = undefined

SpriteComponent

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1515

Sprite Component Properties.

type SpriteComponent = undefined

TextureAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L1088

Represents the data for a Texture asset.

type TextureAssetData = undefined

TextureAtlasAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L1126

Represents the data for a TextureAtlas asset.

type TextureAtlasAssetData = undefined

TextureImportSettings

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/assets.ts#L73

Import settings used when uploading a texture asset.

type TextureImportSettings = undefined

WasmAssetData

Type alias · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/asset.d.ts#L1187

Represents the data for a Wasm asset.

type WasmAssetData = undefined

revision

Variable · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/index.ts#L55

The git revision of the Editor API library. This is a string of the git commit hash.

const revision: "PACKAGE_REVISION" = 'PACKAGE_REVISION'

version

Variable · category: Other

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/index.ts#L50

The version of the Editor API library. This is a string in semantic version format of major.minor.patch.

const version: "PACKAGE_VERSION" = 'PACKAGE_VERSION'

Clipboard

Class · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/clipboard.ts#L9

Represents a custom clipboard with a specific name which stores a value in localStorage under that name

Constructors

constructor

new Clipboard(name: string)

Constructor

Parameters

Accessors

empty

get empty(): boolean

Gets whether the clipboard is empty

value

get value(): string | object
set value(value: string | object)

Gets the value stored in the clipboard.

Guid

Class · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/guid.ts#L7

Basically a very large random number (128-bit) which means the probability of creating two that clash is vanishingly small.

Methods

create

static create(): string

Create an RFC4122 version 4 compliant GUID.

Returns string: A new GUID.

Jobs

Class · extends Events · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/jobs.ts#L10

Facilitates tracking of asynchronous jobs.

Methods

finish

finish(jobId: string): Function

Notifies that a job has finished. The specified job id is removed and the callback stored when the job was started is returned.

Parameters

Returns Function: The function stored when the job was started

Example

const jobId = editor.jobs.start(() => console.log('job was finished'));
editor.jobs.finish(jobId)(); // prints 'job was finished'

start

start(fn: Function): string

Adds a new job. The specified function will be returned when the job is finished.

Parameters

Returns string: Returns a job id

Example

const jobId = editor.jobs.start(() => console.log('job was finished'));
editor.jobs.finish(jobId)(); // prints 'job was finished'

Inherited from Events

LocalStorage

Class · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/localstorage.ts#L6

Wrapper around native local storage

Methods

get

get(key: string): string | object

Gets a key from localStorage

Parameters

Returns string | object: The value

has

has(key: string): boolean

Checks if key exists in local storage

Parameters

Returns boolean: True or false

set

set(key: string, value: string | object): void

Stores a key-value to localStorage

Parameters

unset

unset(key: string): void

Removes a key from localStorage

Parameters

Messenger

Class · extends Events · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/messenger.ts#L42

The Messenger API. The messenger receives messages when various things happen e.g. an asset is created etc.

Constructors

constructor

new Messenger(messenger: MessagerClient)

Constructor

Parameters

Accessors

isConnected

get isConnected(): boolean

Returns true if we are connected to the messenger server.

Methods

connect

connect(url: string): void

Connects to the messenger server.

Parameters

Realtime

Class · extends Events · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/realtime.ts#L12

Provides methods to communicate and load / save data to the realtime server

Accessors

assets

get assets(): RealtimeAssets

Gets the realtime assets API

connection

get connection(): RealtimeConnection

Gets the realtime connection

scenes

get scenes(): RealtimeScenes

Gets the realtime scenes API

RealtimeAsset

Class · extends Events · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/realtime/asset.ts#L11

Represents an asset in sharedb

Constructors

constructor

new RealtimeAsset(uniqueId: number, realtime: Realtime, connection: RealtimeConnection)

Constructor

Parameters

Accessors

data

get data(): any

The asset data

id

get id(): number

The asset id - used in combination with branch id

loaded

get loaded(): boolean

Whether the asset is loaded

uniqueId

get uniqueId(): number

The asset's unique id

Methods

load

load(): void

Loads asset from sharedb and subscribes to changes.

submitOp

submitOp(op: object, callback?: Function): void

Submits sharedb operation

Parameters

unload

unload(): void

Unloads asset from sharedb and unsubscribes from changes.

whenNothingPending

whenNothingPending(callback: Function): void

Calls the callback when there are no changes pending to be sent to the server

Parameters

RealtimeAssets

Class · extends Events · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/realtime/assets.ts#L12

Provides methods to load assets from sharedb

Constructors

constructor

new RealtimeAssets(realtime: Realtime, connection: RealtimeConnection)

Constructor

Parameters

Methods

get

get(id: number): RealtimeAsset

Gets an already loaded asset

Parameters

Returns RealtimeAsset: The asset

load

load(id: number): RealtimeAsset

Loads an asset

Parameters

Returns RealtimeAsset: The asset

unload

unload(id: number): void

Unloads an asset

Parameters

RealtimeConnection

Class · extends Events · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/realtime/connection.ts#L24

Handles connecting and communicating with the Realtime server.

Constructors

constructor

new RealtimeConnection(realtime: Realtime)

Constructor

Parameters

Accessors

authenticated

get authenticated(): boolean

Whether the server has authenticated the user

connected

get connected(): boolean

Whether the user is connected to the server

sharedb

get sharedb(): ShareDb

Gets the sharedb instance

Methods

connect

connect(url: string): void

Connect to the realtime server

Parameters

disconnect

disconnect(): void

Disconnect from the server

endBulkSubscribe

endBulkSubscribe(): void

Stop bulk subscribing to documents

getDocument

getDocument(collection: string, id: number): Doc<any>

Gets a sharedb document

Parameters

Returns Doc<any>: The sharedb document

send

send(data: string): Promise<void>

Sends a string to the server

Parameters

Returns Promise<void>

sendMessage

sendMessage(name: string, data: object): void

Send message to server

Parameters

startBulkSubscribe

startBulkSubscribe(): void

Start bulk subscribing to documents

RealtimeScene

Class · extends Events · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/realtime/scene.ts#L12

Represents a scene in sharedb

Constructors

constructor

new RealtimeScene(uniqueId: number, realtime: Realtime, connection: RealtimeConnection)

Constructor

Parameters

Accessors

data

get data(): any

The scene data

id

get id(): number

The scene id - used in combination with the branch id

loaded

get loaded(): boolean

Whether the scene is loaded

uniqueId

get uniqueId(): number

The scene's unique id

Methods

addEntity

addEntity(entity: Entity): void

Add entity to scene

Parameters

load

load(): void

Loads scene from sharedb and subscribes to changes.

removeEntity

removeEntity(entity: Entity): void

Removes entity from scene (not from children of another entity)

Parameters

submitOp

submitOp(op: object): void

Submits sharedb operation

Parameters

unload

unload(): void

Unloads scene from sharedb and unsubscribes from changes.

whenNothingPending

whenNothingPending(callback: Function): void

Calls the callback when there are no changes pending to be sent to the server

Parameters

RealtimeScenes

Class · extends Events · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/realtime/scenes.ts#L12

Provides methods to load scenes from sharedb

Constructors

constructor

new RealtimeScenes(realtime: Realtime, connection: RealtimeConnection)

Constructor

Parameters

Accessors

current

get current(): RealtimeScene

The current scene

Methods

load

load(sceneId: number): RealtimeScene

Loads a scene

Parameters

Returns RealtimeScene: The scene

unload

unload(sceneId: number): void

Unloads a scene

Parameters

utils

Class · category: Internal

Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/utils.ts#L6

Contains various utility methods

Methods

deepCopy

static deepCopy(data: Record<string, any>): Record<string, any>

Deep copy an object

Parameters

Returns Record<string, any>: A copy of the data