# 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. Index: https://api.playcanvas.com/editor/llms.txt Total Pages: 76 Generated: 2026-10-08 ================================================================================ URL: https://api.playcanvas.com/editor/classes/Asset.md # 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 ```ts new Asset(data?: any) ``` Constructor **Parameters** - `data` (`any`, optional, default `{}`): The asset data ## Accessors ### history ```ts get history(): ObserverHistory ``` Gets observer history for this asset. ### observer ```ts get observer(): AssetObserver ``` The observer object for this asset. ## Methods ### delete ```ts delete(): Promise ``` Deletes this asset. **Returns** `Promise` ### get ```ts get(path: string): any ``` Gets value at path. See the [Asset](https://api.playcanvas.com/editor/classes/Asset.md) overview for a full list of properties. **Parameters** - `path` (`string`): The path **Returns** `any`: The value ### has ```ts has(path: string): boolean ``` Checks if path exists. See the [Asset](https://api.playcanvas.com/editor/classes/Asset.md) overview for a full list of properties. **Parameters** - `path` (`string`): The path **Returns** `boolean`: True if path exists ### insert ```ts insert(path: any, value: any, index: any): boolean ``` Inserts value in array at path, at specified index. See the [Asset](https://api.playcanvas.com/editor/classes/Asset.md) overview for a full list of properties. **Parameters** - `path` (`any`): The path - `value` (`any`): The value - `index` (`any`): The index (if undefined the value will be inserted in the end) **Returns** `boolean`: Whether the value was inserted ### instantiateTemplate ```ts instantiateTemplate(parent: Entity, options?: object): Promise ``` Creates an instance of this template asset. Assumes this asset is a template asset. **Parameters** - `parent` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The parent entity - `options` (`object`, optional, default `{}`) - `options.extraData` (`object`, optional): Extra data passed to the backend. Used by the Editor on specific cases. - `options.history` (`boolean`, optional): Whether to record a history action. - `options.index` (`number`, optional): The desired index under the parent to instantiate the template. - `options.select` (`boolean`, optional): Whether to select the new entity. **Returns** `Promise<`[`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`>`: The new entity. ### json ```ts json(): Record ``` Returns JSON representation of entity data **Returns** `Record`: - The data ### latest ```ts latest(): Asset ``` Returns the latest version of the Asset from the Assets API. **Returns** [`Asset`](https://api.playcanvas.com/editor/classes/Asset.md): The asset ### load ```ts load(): Promise ``` Loads asset from the server without subscribing to realtime changes. **Returns** `Promise` ### loadAndSubscribe ```ts loadAndSubscribe(): Promise ``` Loads the asset's data from sharedb and subscribes to changes. **Returns** `Promise` ### removeValue ```ts removeValue(path: any, value: any): boolean ``` Remove value from array at path. See the [Asset](https://api.playcanvas.com/editor/classes/Asset.md) overview for a full list of properties. **Parameters** - `path` (`any`): The path - `value` (`any`): The value **Returns** `boolean`: Whether the value was removed ### replace ```ts replace(asset: Asset, options?: object): void ``` Replaces any references to this asset with references to the new asset specified. **Parameters** - `asset` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)): The new asset. - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional): Whether to record a history action. ### set ```ts set(path: string, value: any): boolean ``` Sets value at path. See the [Asset](https://api.playcanvas.com/editor/classes/Asset.md) overview for a full list of properties. **Parameters** - `path` (`string`): The path - `value` (`any`): The value **Returns** `boolean`: Whether the value was set ### unset ```ts unset(path: string): boolean ``` Unsets value at path. See the [Asset](https://api.playcanvas.com/editor/classes/Asset.md) overview for a full list of properties. **Parameters** - `path` (`string`): The path **Returns** `boolean`: Whether the value was unset ### getFileUrl ```ts static getFileUrl(id: number, filename: string): string ``` Gets the file URL for an asset file. **Parameters** - `id` (`number`): The asset id - `filename` (`string`): The desired filename **Returns** `string`: The file URL -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/Assets.md # 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 ```ts new Assets(options?: object) ``` Constructor **Parameters** - `options` (`object`, optional, default `{}`) - `options.autoSubscribe` (`boolean`, optional): Whether to auto subscribe to asset changes when assets are loaded. ## Accessors ### defaultUploadCompletedCallback ```ts 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 ```ts 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 ```ts 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 ```ts get parseScriptCallback(): (asset: Asset) => any set parseScriptCallback(value: (asset: Asset) => any) ``` Gets the callback which parses script assets. ## Methods ### add ```ts add(asset: Asset): void ``` Adds asset to the list **Parameters** - `asset` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)): The asset ### clear ```ts clear(): void ``` Removes all assets from the list ### createAnimStateGraph ```ts createAnimStateGraph(options?: object): Promise ``` Creates new anim state graph asset. **Parameters** - `options` (`object`, optional, default `{}`) - `options.data` (`object`, optional): The asset data. See [Asset](https://api.playcanvas.com/editor/classes/Asset.md) for Animstategraph data. - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createBundle ```ts createBundle(options?: object): Promise ``` Creates new bundle asset **Parameters** - `options` (`object`, optional, default `{}`) - `options.assets` (`any[]`, optional): The assets that the bundle will contain - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createCss ```ts createCss(options?: object): Promise ``` Creates new CSS asset **Parameters** - `options` (`object`, optional, default `{}`) - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. - `options.text` (`string`, optional): The CSS **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createCubemap ```ts createCubemap(options?: object): Promise ``` Creates new cubemap asset **Parameters** - `options` (`object`, optional, default `{}`) - `options.anisotropy` (`number`, optional): Cubemap anisotropy value. Defaults to 1. - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.magFilter` (`number`, optional): Cubemap magFilter value. Defaults to pc.FILTER_LINEAR. - `options.minFilter` (`number`, optional): Cubemap minFilter value. Defaults to pc.FILTER_LINEAR_MIPMAP_LINEAR. - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. - `options.textures` (`any[]`, optional): The textures for each cubemap face in this order: right, left, up, down, front, back **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createFolder ```ts createFolder(options: object): Promise ``` Creates a new folder asset **Parameters** - `options` (`object`) - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createHtml ```ts createHtml(options?: object): Promise ``` Creates new HTML asset **Parameters** - `options` (`object`, optional, default `{}`) - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. - `options.text` (`string`, optional): The HTML **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createI18n ```ts createI18n(options?: object): Promise ``` Creates new localization JSON asset **Parameters** - `options` (`object`, optional, default `{}`) - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.localizationData` (`object`, optional): The localization data. If null then default data will be used. - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createJson ```ts createJson(options?: object): Promise ``` Creates new JSON asset **Parameters** - `options` (`object`, optional, default `{}`) - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.json` (`object`, optional): The JSON - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. - `options.spaces` (`number`, optional): The number of spaces used for indentation. Defaults to 0 (tightly packed output). **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createMaterial ```ts createMaterial(options?: object): Promise ``` Creates new material asset **Parameters** - `options` (`object`, optional, default `{}`) - `options.data` (`Record`, optional): The material data. Default values will be used for missing fields. See [Asset](https://api.playcanvas.com/editor/classes/Asset.md) for material data. - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createScript ```ts createScript(options?: object): Promise ``` Creates new script asset **Parameters** - `options` (`object`, optional, default `{}`) - `options.data` (`object`, optional): The script data. See [Asset](https://api.playcanvas.com/editor/classes/Asset.md) for Script data. - `options.filename` (`string`, optional): The filename of the script. This will also be the name of the script asset. If not defined it will be generated from the name of the script. - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. - `options.text` (`string`, optional): The contents of the script. If none then boilerplate code will be used. **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createShader ```ts createShader(options?: object): Promise ``` Creates new shader asset **Parameters** - `options` (`object`, optional, default `{}`) - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. - `options.text` (`string`, optional): The GLSL **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createSprite ```ts createSprite(options?: object): Promise ``` Creates new sprite asset **Parameters** - `options` (`object`, optional, default `{}`) - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.frameKeys` (`any[]`, optional): The sprite's frame keys - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.pixelsPerUnit` (`number`, optional): The sprite's pixels per unit value. Defaults to 100. - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. - `options.renderMode` (`number`, optional): The sprite's render mode. Defaults to pc.SPRITE_RENDERMODE_SIMPLE. - `options.textureAtlas` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The sprite's texture atlas asset **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### createTemplate ```ts createTemplate(options: object): Promise ``` Creates new template asset **Parameters** - `options` (`object`) - `options.entity` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The entity to create the template from - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. **Returns** `Promise`: The new asset ### createText ```ts createText(options?: object): Promise ``` Creates new text asset **Parameters** - `options` (`object`, optional, default `{}`) - `options.folder` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md), optional): The parent folder asset - `options.name` (`string`, optional): The asset name - `options.onProgress` (`Function`, optional): Function to report progress - `options.preload` (`boolean`, optional): Whether to preload the asset. Defaults to true. - `options.text` (`string`, optional): The text **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset ### delete ```ts delete(assets: Asset[]): Promise ``` Deletes specified assets **Parameters** - `assets` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`[]`): The assets **Returns** `Promise` ### filter ```ts filter(fn: Function): any[] ``` Gets assets that satisfy function **Parameters** - `fn` (`Function`): The function (takes an asset as an argument and returns boolean). **Returns** `any[]`: The assets ### findOne ```ts findOne(fn: Function): any ``` Finds first asset that satisfies function **Parameters** - `fn` (`Function`): A function that takes an asset as an argument and returns boolean. **Returns** `any`: The asset ### get ```ts get(id: number): Asset ``` Gets asset by id **Parameters** - `id` (`number`): The asset id **Returns** [`Asset`](https://api.playcanvas.com/editor/classes/Asset.md): The asset ### getAssetForScript ```ts getAssetForScript(script: string): any ``` Gets the first script asset that contains the specified script **Parameters** - `script` (`string`): The script name **Returns** `any`: The script asset ### getUnique ```ts getUnique(uniqueId: number): Asset ``` Gets asset by its unique id **Parameters** - `uniqueId` (`number`): The unique id **Returns** [`Asset`](https://api.playcanvas.com/editor/classes/Asset.md): The asset ### instantiateTemplates ```ts instantiateTemplates(assets: Asset[], parent: Entity, options?: object): Promise ``` Instantiates the specified template assets under the specified parent entity. **Parameters** - `assets` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`[]`): The template assets. - `parent` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The parent entity - `options` (`object`, optional, default `{}`) - `options.extraData` (`object`, optional): Extra data passed to the backend. Used by the Editor on specific cases. - `options.history` (`boolean`, optional): Whether to record a history action. - `options.index` (`number`, optional): The desired index under the parent to instantiate the templates. - `options.select` (`boolean`, optional): Whether to select the new entities. **Returns** `Promise<`[`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`[]>`: The new entities ### list ```ts list(): Asset[] ``` Returns array of all assets **Returns** [`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`[]`: The assets ### listByTag ```ts listByTag(...tags: any[]): any[] ``` Finds all assets with specified tags **Parameters** - `tags` (`any[]`): The tags. If multiple tags are specified then assets that contain ANY of the specified tags will be included. If an argument is an array of tags then assets that contain ALL of the tags in the array will be included. **Returns** `any[]`: The assets ### loadAll ```ts loadAll(options?: object): Promise ``` Loads all assets in the current project / branch. Does not subscribe to realtime changes. **Parameters** - `options` (`object`, optional, default `{}`) - `options.view` (`string`, optional): The desired view for the REST API e.g 'designer', 'shader-editor'. This might limit the assets returned to a smaller subset depending on the view. **Returns** `Promise` ### loadAllAndSubscribe ```ts loadAllAndSubscribe(options?: object): Promise ``` Loads all assets in the current project / branch and subscribes to changes. **Parameters** - `options` (`object`, optional, default `{}`) - `options.view` (`string`, optional): The desired view for the REST API e.g 'designer', 'shader-editor'. This might limit the assets returned to a smaller subset depending on the view. **Returns** `Promise` ### remove ```ts remove(asset: Asset): void ``` Removes asset from the list **Parameters** - `asset` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)): The asset ### upload ```ts upload(data: AssetUploadArguments, settings?: TextureImportSettings | SceneImportSettings, onProgress?: Function): Promise ``` Creates new asset **Parameters** - `data` ([`AssetUploadArguments`](https://api.playcanvas.com/editor/types/AssetUploadArguments.md)): The asset fields - `settings` ([`TextureImportSettings`](https://api.playcanvas.com/editor/types/TextureImportSettings.md) `|` [`SceneImportSettings`](https://api.playcanvas.com/editor/types/SceneImportSettings.md), optional, default `{}`): Import settings - `onProgress` (`Function`, optional, default `null`): Function to report progress **Returns** `Promise<`[`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`>`: The new asset -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/AssetsSchema.md # 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 ```ts new AssetsSchema(schema: Schema) ``` **Parameters** - `schema` ([`Schema`](https://api.playcanvas.com/editor/classes/Schema.md)): The schema API ## Methods ### getDefaultData ```ts getDefaultData(type: string): Record ``` Gets default data for asset type **Parameters** - `type` (`string`): The asset type **Returns** `Record`: The default data ### getFieldsOfType ```ts getFieldsOfType(assetType: string, type: string): string[] ``` Gets a list of fields of a particular type for an asset type **Parameters** - `assetType` (`string`): The type of the asset. - `type` (`string`): The desired type **Returns** `string[]`: A list of fields **Example** ```javascript const materialAssetPaths = editor.schema.assets.getFieldsOfType('material', 'asset'); ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/ComponentSchema.md # 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 ```ts new ComponentSchema(schema: Schema) ``` Creates new instance of API **Parameters** - `schema` ([`Schema`](https://api.playcanvas.com/editor/classes/Schema.md)): The schema API ## Methods ### getDefaultData ```ts getDefaultData(component: string): Record ``` Gets default data for a component **Parameters** - `component` (`string`): The component name **Returns** `Record`: The default data **Example** ```javascript const modelData = editor.schema.components.getDefaultData('model'); ``` ### getFieldsOfType ```ts getFieldsOfType(componentName: string, type: string): string[] ``` Gets a list of fields of a particular type for a component **Parameters** - `componentName` (`string`): The component name - `type` (`string`): The desired type **Returns** `string[]`: A list of fields **Example** ```javascript const buttonEntityFields = editor.schema.components.getFieldsOfType('button', 'entity'); ``` ### list ```ts list(): string[] ``` Gets a list of all the available components **Returns** `string[]`: The components -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/Entities.md # 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 ```ts new Entities() ``` Creates new API instance ## Accessors ### root ```ts get root(): Entity ``` Gets the root Entity ## Methods ### add ```ts add(entity: Entity): void ``` Adds entity to list **Parameters** - `entity` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The entity ### addScript ```ts addScript(entities: Entity[], scriptName: string, options?: object): Promise ``` Like [Entity.addScript](https://api.playcanvas.com/editor/classes/Entity.md#addscript) but works on multiple entities using a single history action. **Parameters** - `entities` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`[]`): The entities. - `scriptName` (`string`): The name of the script. - `options` (`object`, optional, default `{}`) - `options.attributes` (`object`, optional): The values of attributes. Each key is the name of the attributes and each value is the value for that attribute. Leave undefined to let the Editor set default values depending on the attribute types. - `options.history` (`boolean`, optional): Whether to add a history action. Defaults to true. - `options.index` (`number`, optional): The desired index in the entity's scripts order to add this script. **Returns** `Promise`: A promise ### clear ```ts clear(): void ``` Removes all entities from the list ### copyToClipboard ```ts copyToClipboard(entities: Entity[]): void ``` Copy specified entities to localStorage clipboard. Can be used to paste these entities later on. **Parameters** - `entities` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`[]`): The entities ### create ```ts create(data?: CreateEntityArguments, options?: object): Entity ``` Creates new entity and adds it to the hierarchy **Parameters** - `data` ([`CreateEntityArguments`](https://api.playcanvas.com/editor/types/CreateEntityArguments.md), optional, default `null`): Initial data for the entity - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional): Whether to record a history action. Defaults to true. - `options.index` (`number`, optional): The child index that this entity will have under its parent. - `options.select` (`boolean`, optional): Whether to select new Entity. Defaults to false. **Returns** [`Entity`](https://api.playcanvas.com/editor/classes/Entity.md): The new entity **Example** ```javascript const root = editor.entities.create({ name: 'parent', }); const child = editor.entities.create({ name: 'child', parent: root, }); ``` ### delete ```ts delete(entities: Entity | Entity[], options?: object): Promise ``` Delete specified entities **Parameters** - `entities` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md) `|` [`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`[]`): The entities - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional): Whether to record a history action. Defaults to true. **Returns** `Promise` **Example** ```javascript await editor.entities.delete([entity1, entity2]); ``` ### duplicate ```ts duplicate(entities: Entity[], options?: object): Promise ``` Duplicates the specified entities under the same parent **Parameters** - `entities` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`[]`): The entities - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional): Whether to record a history action. Defaults to true. - `options.rename` (`boolean`, optional): Whether to rename the duplicated entities. Defaults to false. - `options.select` (`boolean`, optional): Whether to select the new entities. Defaults to false. **Returns** `Promise<`[`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`[]>`: The duplicated entities **Example** ```ts const duplicated = await editor.entities.duplicate(entities); ``` ### get ```ts get(id: string): Entity ``` Gets entity by resource id **Parameters** - `id` (`string`): The entity's resource id **Returns** [`Entity`](https://api.playcanvas.com/editor/classes/Entity.md): The entity **Example** ```javascript const entity = editor.entities.get(resourceId); ``` ### list ```ts list(): any[] ``` Returns array of all entities **Returns** `any[]`: The entities **Example** ```javascript const entities = editor.entities.list(); console.log(entities.length); ``` ### pasteFromClipboard ```ts pasteFromClipboard(parent: Entity, options?: object): Promise ``` Paste entities copied into clipboard under the specified parent. **Parameters** - `parent` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The parent - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional): Whether to record a history action. Defaults to true. **Returns** `Promise<`[`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`[]>`: The new entities ### remove ```ts remove(entity: Entity, entityReferences?: object): void ``` Removes entity from the list **Parameters** - `entity` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The entity - `entityReferences` (`object`, optional, default `null`): A map of entity references to nullify when this entity is removed ### removeScript ```ts removeScript(entities: Entity[], scriptName: string, options?: object): void ``` Like [Entity.removeScript](https://api.playcanvas.com/editor/classes/Entity.md#removescript) but works on multiple entities using a single history action. **Parameters** - `entities` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`[]`): The entities. - `scriptName` (`string`): The name of the script. - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional): Whether to record a history action. Defaults to true. ### reparent ```ts reparent(data: ReparentArguments[], options?: object): void ``` Reparents entities under new parent. **Parameters** - `data` ([`ReparentArguments`](https://api.playcanvas.com/editor/types/ReparentArguments.md)`[]`): The reparenting data - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional): Whether to record history. Defaults to true - `options.preserveTransform` (`boolean`, optional): Whether to preserve the transform of the entities. Defaults to false. **Example** ```javascript const child = editor.entities.create(); const parent = editor.entities.create(); editor.entities.reparent([{ entity: child, parent: parent }]) ``` ### serverAdd ```ts serverAdd(entityData: object): void ``` Called when an entity is added from the server **Parameters** - `entityData` (`object`): The entity data - `entityData.children` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`[]`) - `entityData.parent` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)) ### serverRemove ```ts serverRemove(entity: Entity): void ``` Called when an entity is removed from the server **Parameters** - `entity` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The entity ### waitToExist ```ts 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** - `entityIds` (`string[]`): The ids of the entities to wait for - `timeoutMs` (`number`): Number of ms to wait before stopping to wait - `callback` (`(entities: Entity[]) => void`): The callback to call when all entities have been added. The signature is (Entity[]) => void. **Returns** `() => void`: Returns a cancel function which can be called to cancel calling the callback when the entities are added. -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/Entity.md # 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 ```ts new Entity(data?: any) ``` Creates new Entity **Parameters** - `data` (`any`, optional, default `{}`): Optional entity data ## Accessors ### children ```ts get children(): Entity[] ``` The children entities. Warning: this creates a new array every time it's called. ### history ```ts get history(): ObserverHistory ``` The history object for this entity. ### observer ```ts get observer(): EntityObserver ``` The observer object for this entity. ### parent ```ts get parent(): Entity ``` The parent entity. ### viewportEntity ```ts get viewportEntity(): any ``` The entity in the 3D viewport of the Editor. ## Methods ### addChild ```ts addChild(entity: Entity): boolean ``` Adds entity as a child **Parameters** - `entity` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The entity **Returns** `boolean`: Whether the child was added ### addComponent ```ts addComponent(component: string, data?: {}): void ``` Adds a component to this Entity **Parameters** - `component` (`string`): The component name - `data` (`{}`, optional, default `{}`): Default component data. Defaults values will be used for any missing fields. For details on component properties see [Entity](https://api.playcanvas.com/editor/classes/Entity.md). **Example** ```javascript editor.entities.root.addComponent('model', { type: 'box' }); ``` ### addScript ```ts addScript(scriptName: string, options?: object): Promise ``` 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** - `scriptName` (`string`): The name of the script. - `options` (`object`, optional, default `{}`) - `options.attributes` (`object`, optional): The values of attributes. Each key is the name of the attributes and each value is the value for that attribute. Leave undefined to let the Editor set default values depending on the attribute types. - `options.history` (`boolean`, optional): Whether to add a history action. Defaults to true. - `options.index` (`number`, optional): The desired index in the entity's scripts order to add this script. **Returns** `Promise`: A promise ### delete ```ts delete(options?: object): Promise ``` Deletes entity (and its children) **Parameters** - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional): Whether to record a history action. Defaults to true. **Returns** `Promise`: A promise **Example** ```javascript editor.entities.root.findByName('door').delete(); ``` ### depthFirst ```ts depthFirst(fn: (entity: Entity) => void): void ``` Executes function for this entity and its children in depth first order. **Parameters** - `fn` (`(entity: Entity) => void`): A function that takes an entity as an argument **Example** ```javascript // get a list of all entities in the graph in depth first order const entities = []; editor.entities.root.depthFirst(entity => entities.push(entity)); ``` ### duplicate ```ts duplicate(options?: object): Promise ``` Duplicates entity under the same parent **Parameters** - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional): Whether to record a history action. Defaults to true. - `options.rename` (`boolean`, optional): Whether to rename the duplicated entity. Defaults to false. - `options.select` (`boolean`, optional): Whether to select the new entity. Defaults to false. **Returns** `Promise<`[`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`>`: The new entity ### filter ```ts filter(fn: (entity: Entity) => boolean): Entity[] ``` Returns the entity and children that satisfy the function **Parameters** - `fn` (`(entity: Entity) => boolean`): A function that takes an Entity and returns whether it should be included in the result **Returns** [`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`[]`: The result **Example** ```javascript const doors = editor.entities.root.filter(entity => entity.get('name').startsWith('door')); ``` ### findByName ```ts findByName(name: string): Entity ``` Finds first entity by name using depth-first search **Parameters** - `name` (`string`): The name **Returns** [`Entity`](https://api.playcanvas.com/editor/classes/Entity.md): The entity **Example** ```javascript const door = editor.entities.root.findByName('Door'); ``` ### get ```ts get(path: string): any ``` Gets value at path. See [Entity](https://api.playcanvas.com/editor/classes/Entity.md) for a list of properties. **Parameters** - `path` (`string`): The path **Returns** `any`: The value **Example** ```javascript console.log(entity.get('position')); ``` ### has ```ts has(path: string): boolean ``` Checks if path exists. See [Entity](https://api.playcanvas.com/editor/classes/Entity.md) for a list of properties. **Parameters** - `path` (`string`): The path **Returns** `boolean`: True if path exists **Example** ```javascript console.log(entity.has('components.model')); ``` ### insert ```ts insert(path: string, value: any, index?: number): boolean ``` Inserts value in array at path, at specified index. See [Entity](https://api.playcanvas.com/editor/classes/Entity.md) for a list of properties. **Parameters** - `path` (`string`): The path - `value` (`any`): The value - `index` (`number`, optional): The index (if undefined the value will be inserted in the end) **Returns** `boolean`: Whether the value was inserted **Example** ```javascript entity.insert('tags', 'a_tag'); ``` ### insertChild ```ts insertChild(entity: Entity, index?: number): boolean ``` Inserts entity as a child at specified index. **Parameters** - `entity` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The entity - `index` (`number`, optional, default `undefined`): The index. If undefined the child will be added in the end. **Returns** `boolean`: Whether the child was added ### isDescendantOf ```ts isDescendantOf(parent: Entity): boolean ``` Returns true if this entity is a descendant of the specified parent entity. **Parameters** - `parent` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The parent **Returns** `boolean`: True if it is ### json ```ts json(): Record ``` Returns JSON representation of entity data **Returns** `Record`: - The data ```javascript console.log(entity.json()); ``` ### jsonHierarchy ```ts 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** ```javascript const data = entity.jsonHierarchy(); console.log(data.children[0].name); ``` ### latest ```ts latest(): Entity ``` Returns the latest version of the Entity from the Entities API. **Returns** [`Entity`](https://api.playcanvas.com/editor/classes/Entity.md): The entity ### listByTag ```ts listByTag(...tags: any[]): Entity[] ``` Finds all entities with specified tags **Parameters** - `tags` (`any[]`): The tags. If multiple tags are specified then entities that contain ANY of the specified tags will be included. If an argument is an array of tags then entities that contain ALL of the tags in the array will be included. **Returns** [`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)`[]`: The entities **Example** ```javascript // 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 ```ts removeChild(entity: Entity): void ``` Removes entity from children **Parameters** - `entity` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The entity ### removeComponent ```ts removeComponent(component: string): void ``` Removes a component from this Entity **Parameters** - `component` (`string`): The component name **Example** ```javascript editor.entities.root.removeComponent('model'); ``` ### removeScript ```ts removeScript(scriptName: string, options?: object): void ``` Removes a script from the entity's script component. **Parameters** - `scriptName` (`string`): The name of the script. - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional): Whether to record a history action. Defaults to true. ### removeValue ```ts removeValue(path: string, value: any): boolean ``` Remove value from array at path. See [Entity](https://api.playcanvas.com/editor/classes/Entity.md) for a list of properties. **Parameters** - `path` (`string`): The path - `value` (`any`): The value **Returns** `boolean`: Whether the value was removed **Example** ```javascript entity.removeValue('tags', 'a_tag'); ``` ### reparent ```ts reparent(parent: Entity, index?: number, options?: object): void ``` Reparents entity under new parent **Parameters** - `parent` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The new parent - `index` (`number`, optional, default `null`): The desired index. If undefined the entity will be added at the end of the parent's children. - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional): Whether to record a history action. Defaults to true. - `options.preserveTransform` (`boolean`, optional): Whether to preserve the original transform after reparenting **Example** ```javascript 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 ```ts set(path: string, value: any): boolean ``` Sets value at path. See [Entity](https://api.playcanvas.com/editor/classes/Entity.md) for a list of properties. **Parameters** - `path` (`string`): The path - `value` (`any`): The value **Returns** `boolean`: Whether the value was set **Example** ```javascript entity.set('position', [1, 0, 0]); ``` ### unset ```ts unset(path: string): boolean ``` Unsets value at path. See [Entity](https://api.playcanvas.com/editor/classes/Entity.md) for a list of properties. **Parameters** - `path` (`string`): The path **Returns** `boolean`: Whether the value was unset **Example** ```javascript entity.unset('components.model'); ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/globals.md # globals Class · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/globals.ts#L16 Global variables ## Properties ### accessToken ```ts static accessToken: string ``` The user's access token ### apiUrl ```ts static apiUrl: string = '' ``` The REST API URL ### assets ```ts static assets: Assets ``` The assets API ### branchId ```ts static branchId: string ``` The current branch id ### clipboard ```ts static clipboard: Clipboard ``` The main clipboard ### entities ```ts static entities: Entities ``` The entities API ### hasLegacyScripts ```ts static hasLegacyScripts: boolean ``` Whether this project is using legacy scripts ### history ```ts static history: History ``` The history API ### homeUrl ```ts static homeUrl: string = '' ``` The home URL ### jobs ```ts static jobs: Jobs ``` The jobs API ### messenger ```ts static messenger: Messenger ``` The messenger API ### projectId ```ts static projectId: number ``` The current project id ### realtime ```ts static realtime: Realtime ``` The realtime API ### schema ```ts static schema: Schema ``` The schema API ### selection ```ts static selection: Selection ``` The selection API ### settings ```ts static settings: Settings ``` The settings API ## Methods ### confirmFn ```ts static confirmFn(text: string, options?: object): Promise ``` 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** - `text` (`string`): The confirm dialog text - `options` (`object`, optional, default `{}`): Options for the popup - `options.noDismiss` (`boolean`, optional): If true then user cannot dismiss the popup and will have to click yes or no - `options.noText` (`boolean`, optional): Text for 'no' option - `options.yesText` (`string`, optional): Text for 'yes' option **Returns** `Promise`: True if the user confirmed, false otherwise -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/History.md # 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 ```ts new History() ``` Creates new instance of the API ## Accessors ### canRedo ```ts get canRedo(): boolean set canRedo(value: boolean) ``` Gets whether there are actions to redo. ### canUndo ```ts get canUndo(): boolean set canUndo(value: boolean) ``` Gets whether there are actions to undo. ### currentAction ```ts get currentAction(): HistoryAction ``` Gets the current action ### lastAction ```ts get lastAction(): HistoryAction ``` Gets the last action ## Methods ### add ```ts add(action: HistoryAction): void ``` Adds history action **Parameters** - `action` (`HistoryAction`): The action **Example** ```javascript 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 ```ts addAndExecute(action: HistoryAction): void ``` Adds history action and execute redo **Parameters** - `action` (`HistoryAction`): The action **Example** ```javascript 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 ```ts clear(): void ``` Clear history **Example** ```javascript editor.history.clear(); ``` ### redo ```ts redo(): void ``` Redo last action **Example** ```javascript editor.history.redo(); ``` ### undo ```ts undo(): void ``` Undo last action **Example** ```javascript editor.history.undo(); ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/SceneSchema.md # 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 ```ts new SceneSchema(schema: Schema) ``` Creates new instance of API **Parameters** - `schema` ([`Schema`](https://api.playcanvas.com/editor/classes/Schema.md)): The schema API ## Methods ### getDefaultPhysicsSettings ```ts getDefaultPhysicsSettings(): Record ``` Get the default physics scene settings for the project **Returns** `Record`: The default physics scene settings **Example** ```javascript const scenePhysicsSettings = editor.schema.scene.getDefaultPhysicsSettings(); ``` ### getDefaultRenderSettings ```ts getDefaultRenderSettings(): Record ``` Get the default render scene settings for the project **Returns** `Record`: The default physics scene settings **Example** ```javascript const sceneRenderSettings = editor.schema.scene.getDefaultRenderSettings(); ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/SceneSettings.md # 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 ```ts new SceneSettings() ``` Creates new instance of the API ## Accessors ### history ```ts get history(): ObserverHistory ``` Gets the history object for this entity ## Methods ### get ```ts get(path: string): any ``` Gets value at path. See the [SceneSettings](https://api.playcanvas.com/editor/classes/SceneSettings.md) overview for a full list of properties. **Parameters** - `path` (`string`): The path **Returns** `any`: The value **Example** ```javascript console.log(editor.settings.scene.get('render.fog')); ``` ### has ```ts has(path: string): boolean ``` Checks if path exists. See the [SceneSettings](https://api.playcanvas.com/editor/classes/SceneSettings.md) overview for a full list of properties. **Parameters** - `path` (`string`): The path **Returns** `boolean`: True if path exists **Example** ```javascript console.log(editor.settings.scene.has('render.fog')); ``` ### json ```ts json(): Record ``` Returns JSON representation of scene settings data **Returns** `Record`: - The data **Example** ```javascript console.log(editor.settings.scene.json()); ``` ### set ```ts set(path: string, value: any): boolean ``` Sets value at path. See the [SceneSettings](https://api.playcanvas.com/editor/classes/SceneSettings.md) overview for a full list of properties. **Parameters** - `path` (`string`): The path - `value` (`any`): The value **Returns** `boolean`: Whether the value was set **Example** ```javascript editor.settings.scene.set('render.fog', 'none'); ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/Schema.md # 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 ```ts new Schema(schema: any) ``` Creates new instance of API **Parameters** - `schema` (`any`) ## Accessors ### assets ```ts get assets(): AssetsSchema ``` Gets the assets schema ### components ```ts get components(): ComponentSchema ``` Gets the component schema ### scene ```ts get scene(): SceneSchema ``` Gets the scene schema ### schema ```ts get schema(): any ``` Gets the schema ### settings ```ts get settings(): SettingsSchema ``` Gets the settings schema ## Methods ### getType ```ts getType(field: any, fixedLength?: number): string ``` Converts the specified schema field to a type recursively. **Parameters** - `field` (`any`) - `fixedLength` (`number`, optional, default `0`) **Returns** `string` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/Selection.md # 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 ```ts new Selection() ``` Constructor ## Accessors ### count ```ts get count(): number ``` Gets the number of selected items ### enabled ```ts get enabled(): boolean set enabled(value: boolean) ``` Gets enabled state of the selection methods. ### history ```ts get history(): SelectionHistory ``` Gets the selection history ### item ```ts get item(): Entity | Asset ``` Gets the first selected item. Short for this.items[0]. ### items ```ts get items(): (Entity | Asset)[] ``` Gets the selected items. This creates a new array every time it is called. **Example** ```javascript editor.selection.items.add(editor.entities.root); const selectedEntities = editor.selection.items; ``` ## Methods ### add ```ts add(item: any, options?: object): void ``` Add item to selection **Parameters** - `item` (`any`) - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional) **Example** ```javascript // add root entity to selection editor.selection.add(editor.entities.root); ``` ### clear ```ts clear(options?: object): void ``` Clears selection **Parameters** - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional) **Example** ```javascript editor.selection.clear(); ``` ### has ```ts has(item: any): boolean ``` Checks if item is in selection **Parameters** - `item` (`any`) **Returns** `boolean` **Example** ```javascript const isRootSelected = editor.selection.has(editor.entities.root); ``` ### remove ```ts remove(item: any, options?: object): void ``` Remove item from selection **Parameters** - `item` (`any`) - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional) **Example** ```javascript // remove root entity from selection editor.selection.remove(editor.entities.root); ``` ### set ```ts set(items: any[], options?: object): void ``` Sets current selection **Parameters** - `items` (`any[]`) - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional) **Example** ```javascript // select root entity editor.selection.set([editor.entities.root]); ``` ### toggle ```ts toggle(item: any, options?: object): void ``` Toggle item selection **Parameters** - `item` (`any`) - `options` (`object`, optional, default `{}`) - `options.history` (`boolean`, optional) **Example** ```javascript // toggle root entity selection editor.selection.toggle(editor.entities.root); ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/SelectionHistory.md # 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 ```ts new SelectionHistory(selection: Selection) ``` Constructor **Parameters** - `selection` ([`Selection`](https://api.playcanvas.com/editor/classes/Selection.md)) ## Accessors ### enabled ```ts get enabled(): boolean set enabled(value: boolean) ``` Gets enabled state of selection undo / redo. ## Methods ### wrapAction ```ts wrapAction(name: any, fn: () => void): void ``` Record history action after executing function. The history action will restore the previous selection. **Parameters** - `name` (`any`) - `fn` (`() => void`) -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/Settings.md # 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 ```ts new Settings() ``` Creates new API instance ## Accessors ### scene ```ts get scene(): SceneSettings ``` Gets the settings for the currently loaded scene. -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/SettingsSchema.md # 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 ```ts new SettingsSchema(schema: Schema) ``` Creates new instance of API **Parameters** - `schema` ([`Schema`](https://api.playcanvas.com/editor/classes/Schema.md)): The schema API ## Methods ### getDefaultProjectSettings ```ts getDefaultProjectSettings(): Record ``` Get the default settings for the project **Returns** `Record`: The default settings for the project **Example** ```javascript const projectSettings = editor.schema.settings.getDefaultProjectSettings(); ``` ### getDefaultProjectUserSettings ```ts getDefaultProjectUserSettings(): Record ``` Get the default settings for the user in the project **Returns** `Record`: The default settings for the user in the project **Example** ```javascript const projectUserSettings = editor.schema.settings.getDefaultProjectUserSettings(); ``` ### getDefaultUserSettings ```ts getDefaultUserSettings(): Record ``` Get the default settings for the user **Returns** `Record`: The default settings for the user **Example** ```javascript const userSettings = editor.schema.settings.getDefaultUserSettings(); ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/AnimationAssetData.md # 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. ```ts type AnimationAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/AnimationComponent.md # AnimationComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L158 Animation Component Properties. ```ts type AnimationComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/AnimComponent.md # AnimComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L94 Anim Component Properties. ```ts type AnimComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/AnimstategraphAssetData.md # 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. ```ts type AnimstategraphAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/AssetData.md # 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. ```ts type AssetData = AnimationAssetData | AnimstategraphAssetData | BundleAssetData | CubemapAssetData | FontAssetData | MaterialAssetData | ModelAssetData | RenderAssetData | ScriptAssetData | SpriteAssetData | TextureAssetData | TextureAtlasAssetData | WasmAssetData ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/AssetObserver.md # 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. ```ts type AssetObserver = Observer & { apiAsset: Asset; history: ObserverHistory } ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/AssetProps.md # 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](https://api.playcanvas.com/editor/classes/Asset.md#get) and [Asset#set](https://api.playcanvas.com/editor/classes/Asset.md#set). ```ts type AssetProps = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/AssetUploadArguments.md # 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. ```ts type AssetUploadArguments = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/AudioListenerComponent.md # AudioListenerComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L189 AudioListener Component Properties. ```ts type AudioListenerComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/BundleAssetData.md # 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. ```ts type BundleAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/ButtonComponent.md # ButtonComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L200 Button Component Properties. ```ts type ButtonComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/CameraComponent.md # CameraComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L281 Camera Component Properties. ```ts type CameraComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/CollisionComponent.md # CollisionComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L352 Collision Component Properties. ```ts type CollisionComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/Components.md # Components Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L68 Components of an Entity. ```ts type Components = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/CreateEntityArguments.md # CreateEntityArguments Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/entities.ts#L18 Data to create a new Entity ```ts type CreateEntityArguments = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/CubemapAssetData.md # 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. ```ts type CubemapAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/ElementComponent.md # ElementComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L398 Element Component Properties. ```ts type ElementComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/EntityObserver.md # 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. ```ts type EntityObserver = Observer & { apiEntity: Entity; entity: any; history: ObserverHistory; latestFn: () => Observer } ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/EntityProps.md # 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](https://api.playcanvas.com/editor/classes/Entity.md#get) and [Entity#set](https://api.playcanvas.com/editor/classes/Entity.md#set). Common Entity Properties: ```ts type EntityProps = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/FontAssetData.md # 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. ```ts type FontAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/LayoutChildComponent.md # LayoutChildComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L599 LayoutChild Component Properties. ```ts type LayoutChildComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/LayoutGroupComponent.md # LayoutGroupComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L645 LayoutGroup Component Properties. ```ts type LayoutGroupComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/LightComponent.md # LightComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L701 Light Component Properties. ```ts type LightComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/MaterialAssetData.md # 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. ```ts type MaterialAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/MessagerClient.md # 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. ```ts type MessagerClient = Events & { isConnected: boolean; authenticate: any; connect: any; projectWatch: any } ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/ModelAssetData.md # 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. ```ts type ModelAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/ModelComponent.md # ModelComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L831 Model Component Properties. ```ts type ModelComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/ParticleSystemComponent.md # ParticleSystemComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L909 ParticleSystem Component Properties. ```ts type ParticleSystemComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/RenderAssetData.md # 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. ```ts type RenderAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/RenderComponent.md # RenderComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1120 Render Component Properties. ```ts type RenderComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/ReparentArguments.md # 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 ```ts type ReparentArguments = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/RigidBodyComponent.md # RigidBodyComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1199 RigidBody Component Properties. ```ts type RigidBodyComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/SceneImportSettings.md # 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.). ```ts type SceneImportSettings = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/SceneSettingsObserver.md # 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. ```ts type SceneSettingsObserver = Observer & { history: ObserverHistory } ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/SceneSettingsProps.md # 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. ```ts type SceneSettingsProps = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/ScreenComponent.md # ScreenComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1250 Screen Component Properties. ```ts type ScreenComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/ScriptAssetData.md # 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. ```ts type ScriptAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/ScriptComponent.md # ScriptComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1286 Script Component Properties. ```ts type ScriptComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/ScrollbarComponent.md # ScrollbarComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1319 Scrollbar Component Properties. ```ts type ScrollbarComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/ScrollviewComponent.md # ScrollviewComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1350 Scrollview Component Properties. ```ts type ScrollviewComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/SoundComponent.md # SoundComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1426 Sound Component Properties. ```ts type SoundComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/SpriteAssetData.md # 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. ```ts type SpriteAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/SpriteComponent.md # SpriteComponent Type alias · category: Other Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/external/types/entity.d.ts#L1515 Sprite Component Properties. ```ts type SpriteComponent = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/TextureAssetData.md # 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. ```ts type TextureAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/TextureAtlasAssetData.md # 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. ```ts type TextureAtlasAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/TextureImportSettings.md # 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. ```ts type TextureImportSettings = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/types/WasmAssetData.md # 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. ```ts type WasmAssetData = undefined ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/variables/revision.md # 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. ```ts const revision: "PACKAGE_REVISION" = 'PACKAGE_REVISION' ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/variables/version.md # 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`. ```ts const version: "PACKAGE_VERSION" = 'PACKAGE_VERSION' ``` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/Clipboard.md # 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 ```ts new Clipboard(name: string) ``` Constructor **Parameters** - `name` (`string`): The name of the clipboard. ## Accessors ### empty ```ts get empty(): boolean ``` Gets whether the clipboard is empty ### value ```ts get value(): string | object set value(value: string | object) ``` Gets the value stored in the clipboard. -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/Guid.md # 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 ```ts static create(): string ``` Create an RFC4122 version 4 compliant GUID. **Returns** `string`: A new GUID. -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/Jobs.md # 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 ```ts 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** - `jobId` (`string`): The job id **Returns** `Function`: The function stored when the job was started **Example** ```javascript const jobId = editor.jobs.start(() => console.log('job was finished')); editor.jobs.finish(jobId)(); // prints 'job was finished' ``` ### start ```ts start(fn: Function): string ``` Adds a new job. The specified function will be returned when the job is finished. **Parameters** - `fn` (`Function`): A function to be stored for this job. **Returns** `string`: Returns a job id **Example** ```javascript const jobId = editor.jobs.start(() => console.log('job was finished')); editor.jobs.finish(jobId)(); // prints 'job was finished' ``` ## Inherited from Events - `new Jobs()` -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/LocalStorage.md # LocalStorage Class · category: Internal Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/localstorage.ts#L6 Wrapper around native local storage ## Methods ### get ```ts get(key: string): string | object ``` Gets a key from localStorage **Parameters** - `key` (`string`): The key **Returns** `string | object`: The value ### has ```ts has(key: string): boolean ``` Checks if key exists in local storage **Parameters** - `key` (`string`): The key **Returns** `boolean`: True or false ### set ```ts set(key: string, value: string | object): void ``` Stores a key-value to localStorage **Parameters** - `key` (`string`): The key - `value` (`string | object`): The value ### unset ```ts unset(key: string): void ``` Removes a key from localStorage **Parameters** - `key` (`string`): The key -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/Messenger.md # 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 ```ts new Messenger(messenger: MessagerClient) ``` Constructor **Parameters** - `messenger` ([`MessagerClient`](https://api.playcanvas.com/editor/types/MessagerClient.md)): The instance of the Messenger client - this is a different class which requires the Messenger client library to be downloaded. ## Accessors ### isConnected ```ts get isConnected(): boolean ``` Returns true if we are connected to the messenger server. ## Methods ### connect ```ts connect(url: string): void ``` Connects to the messenger server. **Parameters** - `url` (`string`): The server URL -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/Realtime.md # 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 ```ts get assets(): RealtimeAssets ``` Gets the realtime assets API ### connection ```ts get connection(): RealtimeConnection ``` Gets the realtime connection ### scenes ```ts get scenes(): RealtimeScenes ``` Gets the realtime scenes API -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/RealtimeAsset.md # 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 ```ts new RealtimeAsset(uniqueId: number, realtime: Realtime, connection: RealtimeConnection) ``` Constructor **Parameters** - `uniqueId` (`number`): The unique asset id - `realtime` ([`Realtime`](https://api.playcanvas.com/editor/classes/Realtime.md)): The realtime API - `connection` ([`RealtimeConnection`](https://api.playcanvas.com/editor/classes/RealtimeConnection.md)): The realtime connection ## Accessors ### data ```ts get data(): any ``` The asset data ### id ```ts get id(): number ``` The asset id - used in combination with branch id ### loaded ```ts get loaded(): boolean ``` Whether the asset is loaded ### uniqueId ```ts get uniqueId(): number ``` The asset's unique id ## Methods ### load ```ts load(): void ``` Loads asset from sharedb and subscribes to changes. ### submitOp ```ts submitOp(op: object, callback?: Function): void ``` Submits sharedb operation **Parameters** - `op` (`object`): The operation - `callback` (`Function`, optional): The callback ### unload ```ts unload(): void ``` Unloads asset from sharedb and unsubscribes from changes. ### whenNothingPending ```ts whenNothingPending(callback: Function): void ``` Calls the callback when there are no changes pending to be sent to the server **Parameters** - `callback` (`Function`): The callback -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/RealtimeAssets.md # 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 ```ts new RealtimeAssets(realtime: Realtime, connection: RealtimeConnection) ``` Constructor **Parameters** - `realtime` ([`Realtime`](https://api.playcanvas.com/editor/classes/Realtime.md)): The realtime API - `connection` ([`RealtimeConnection`](https://api.playcanvas.com/editor/classes/RealtimeConnection.md)): The realtime connection ## Methods ### get ```ts get(id: number): RealtimeAsset ``` Gets an already loaded asset **Parameters** - `id` (`number`): The asset's unique id **Returns** [`RealtimeAsset`](https://api.playcanvas.com/editor/classes/RealtimeAsset.md): The asset ### load ```ts load(id: number): RealtimeAsset ``` Loads an asset **Parameters** - `id` (`number`): The asset's unique id **Returns** [`RealtimeAsset`](https://api.playcanvas.com/editor/classes/RealtimeAsset.md): The asset ### unload ```ts unload(id: number): void ``` Unloads an asset **Parameters** - `id` (`number`): The asset's unique id -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/RealtimeConnection.md # 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 ```ts new RealtimeConnection(realtime: Realtime) ``` Constructor **Parameters** - `realtime` ([`Realtime`](https://api.playcanvas.com/editor/classes/Realtime.md)): The realtime API ## Accessors ### authenticated ```ts get authenticated(): boolean ``` Whether the server has authenticated the user ### connected ```ts get connected(): boolean ``` Whether the user is connected to the server ### sharedb ```ts get sharedb(): ShareDb ``` Gets the sharedb instance ## Methods ### connect ```ts connect(url: string): void ``` Connect to the realtime server **Parameters** - `url` (`string`): The server URL ### disconnect ```ts disconnect(): void ``` Disconnect from the server ### endBulkSubscribe ```ts endBulkSubscribe(): void ``` Stop bulk subscribing to documents ### getDocument ```ts getDocument(collection: string, id: number): Doc ``` Gets a sharedb document **Parameters** - `collection` (`string`): The collection name - `id` (`number`): The document id **Returns** `Doc`: The sharedb document ### send ```ts send(data: string): Promise ``` Sends a string to the server **Parameters** - `data` (`string`): The message data **Returns** `Promise` ### sendMessage ```ts sendMessage(name: string, data: object): void ``` Send message to server **Parameters** - `name` (`string`): The message name - `data` (`object`): The message data ### startBulkSubscribe ```ts startBulkSubscribe(): void ``` Start bulk subscribing to documents -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/RealtimeScene.md # 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 ```ts new RealtimeScene(uniqueId: number, realtime: Realtime, connection: RealtimeConnection) ``` Constructor **Parameters** - `uniqueId` (`number`): The unique scene id - `realtime` ([`Realtime`](https://api.playcanvas.com/editor/classes/Realtime.md)): The realtime API - `connection` ([`RealtimeConnection`](https://api.playcanvas.com/editor/classes/RealtimeConnection.md)): The realtime connection ## Accessors ### data ```ts get data(): any ``` The scene data ### id ```ts get id(): number ``` The scene id - used in combination with the branch id ### loaded ```ts get loaded(): boolean ``` Whether the scene is loaded ### uniqueId ```ts get uniqueId(): number ``` The scene's unique id ## Methods ### addEntity ```ts addEntity(entity: Entity): void ``` Add entity to scene **Parameters** - `entity` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The entity ### load ```ts load(): void ``` Loads scene from sharedb and subscribes to changes. ### removeEntity ```ts removeEntity(entity: Entity): void ``` Removes entity from scene (not from children of another entity) **Parameters** - `entity` ([`Entity`](https://api.playcanvas.com/editor/classes/Entity.md)): The entity ### submitOp ```ts submitOp(op: object): void ``` Submits sharedb operation **Parameters** - `op` (`object`): The operation ### unload ```ts unload(): void ``` Unloads scene from sharedb and unsubscribes from changes. ### whenNothingPending ```ts whenNothingPending(callback: Function): void ``` Calls the callback when there are no changes pending to be sent to the server **Parameters** - `callback` (`Function`): The callback -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/RealtimeScenes.md # 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 ```ts new RealtimeScenes(realtime: Realtime, connection: RealtimeConnection) ``` Constructor **Parameters** - `realtime` ([`Realtime`](https://api.playcanvas.com/editor/classes/Realtime.md)): The realtime API - `connection` ([`RealtimeConnection`](https://api.playcanvas.com/editor/classes/RealtimeConnection.md)): The realtime connection ## Accessors ### current ```ts get current(): RealtimeScene ``` The current scene ## Methods ### load ```ts load(sceneId: number): RealtimeScene ``` Loads a scene **Parameters** - `sceneId` (`number`): The scene id **Returns** [`RealtimeScene`](https://api.playcanvas.com/editor/classes/RealtimeScene.md): The scene ### unload ```ts unload(sceneId: number): void ``` Unloads a scene **Parameters** - `sceneId` (`number`): The scene id -------------------------------------------------------------------------------- URL: https://api.playcanvas.com/editor/classes/utils.md # utils Class · category: Internal Source: https://github.com/playcanvas/editor-api/blob/4303c34bcee9a418297350899ad3a3f555526ec4/src/utils.ts#L6 Contains various utility methods ## Methods ### deepCopy ```ts static deepCopy(data: Record): Record ``` Deep copy an object **Parameters** - `data` (`Record`): The data to copy **Returns** `Record`: A copy of the data --------------------------------------------------------------------------------