# 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<Asset>
```

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<Asset>
```

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<Asset>
```

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<Asset>
```

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<Asset>
```

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<Asset>
```

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<Asset>
```

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<Asset>
```

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<Asset>
```

Creates new material asset

**Parameters**

- `options` (`object`, optional, default `{}`)
    - `options.data` (`Record<string, any>`, 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<Asset>
```

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<Asset>
```

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<Asset>
```

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<void>
```

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<void>`: The new asset

### createText

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

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<void>
```

Deletes specified assets

**Parameters**

- `assets` ([`Asset`](https://api.playcanvas.com/editor/classes/Asset.md)`[]`): The assets

**Returns** `Promise<void>`

### 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<Entity[]>
```

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<void>
```

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<void>`

### loadAllAndSubscribe

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

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<void>`

### 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<Asset>
```

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
