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

Deletes this asset.

**Returns** `Promise<void>`

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

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<string, any>
```

Returns JSON representation of entity data

**Returns** `Record<string, any>`: - 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<void>
```

Loads asset from the server without subscribing to realtime changes.

**Returns** `Promise<void>`

### loadAndSubscribe

```ts
loadAndSubscribe(): Promise<void>
```

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

**Returns** `Promise<void>`

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