# Asset Containers

> Learn all about using asset containers in Babylon.js.

Source: https://doc.babylonjs.com/features/featuresDeepDive/importers/assetContainers

An AssetContainer can be used to manage a list of assets (like nodes, cameras, lights, meshes, etc.). These assets are still linked to a scene but are not taken into account. Consider asset containers as pools of entities.

## Creating an AssetContainer

It can be created manually:

```javascript
const container = new BABYLON.AssetContainer(scene);
```

Or by loading from a file. See [loading from files](https://doc.babylonjs.com/features/featuresDeepDive/importers/loadingFileTypes).

## Adding or removing assets to the scene

The container can then be used to add or remove contents of the container from the scene.

```javascript
// Add all objects in the asset container to the scene
container.addAllToScene();

// Remove all objects in the container from the scene
container.removeAllFromScene();
```

- [Playground: Asset Container Adding and Removing Assets](https://playground.babylonjs.com/#5NFRVE#1) - Simple Example of adding and removing asset container assets into your scene.

This can be used to add/remove all objects in a scene without the need to exit WebVR. [Playground: Asset Container Adding and Removing Assets in WebVR](https://playground.babylonjs.com/#JA1ND3#1016) - Simple Example of adding and removing asset container assets into your WebVR scene.

When creating assets manually, the `moveAllFromScene` method can be used to move all assets currently in a scene into an AssetContainer and remove them from the scene for later use.

```javascript
const keepAssets = new BABYLON.KeepAssets();
keepAssets.cameras.push(camera);
container.moveAllFromScene(keepAssets);
```

- [Playground: Moving Assets Into an Asset Container](https://playground.babylonjs.com/#5NFRVE#3) - Simple Example of moving assets in a scene into an asset container.

## Duplicating Models

Asset containers can also be used as "templates" to duplicate models without reloading them.

To do so, you only need to call:

```javascript
let entries = container.instantiateModelsToScene();
```

The returned `entries` object will contain:

- rootNodes: A list of all the root nodes created by the duplication process
- skeletons: A list of all the skeletons created by the duplication process
- animationGroups: A list of all the animation groups created by the duplication process

- [Playground: Instantiating Asset Container Assets](https://playground.babylonjs.com/#S7E00P#439) - Simple Example of using asset containers as templates to duplicate assets in a scene.

You can also set two parameters to the call to `instantiateModelsToScene`:

- nameFunction: This lets you decide what the names of the cloned entities will be (instead of "Clone of...")
- cloneMaterials: By default, materials are not cloned but shared. With this parameter, you can force the system to also clone the materials.

```javascript
const entries = container.instantiateModelsToScene((name) => "p" + name, true);
```

You can dispose a specific set of instantiated models again with:

```javascript
entries.dispose();
```
