# ContainerResource

Class · category: Graphics

Source: https://github.com/playcanvas/engine/blob/b5b983982a9860d21e0c1dafb2f85f72e2c01afb/src/framework/handlers/container.js#L23

Container for a list of animations, textures, materials, renders, gsplats and a model.

## Methods

### applyMaterialVariant

```ts
applyMaterialVariant(entity: Entity, name?: string): void
```

Applies a material variant to an entity hierarchy.

**Parameters**

- `entity` ([`Entity`](https://api.playcanvas.com/engine/classes/Entity.md)): The entity root to which material variants will be applied.
- `name` (`string`, optional): The name of the variant, as queried from getMaterialVariants, if
  null the variant will be reset to the default.

**Example**

```ts
// load a glb file and instantiate an entity with a render component based on it
app.assets.loadFromUrl("statue.glb", "container", (err, asset) => {
    const entity = asset.resource.instantiateRenderEntity({
        castShadows: true
    });
    app.root.addChild(entity);
    const materialVariants = asset.resource.getMaterialVariants();
    asset.resource.applyMaterialVariant(entity, materialVariants[0]);
});
```

### applyMaterialVariantInstances

```ts
applyMaterialVariantInstances(instances: MeshInstance[], name?: string): void
```

Applies a material variant to a set of mesh instances. Compared to the applyMaterialVariant,
this method allows for setting the variant on a specific set of mesh instances instead of the
whole entity.

**Parameters**

- `instances` ([`MeshInstance`](https://api.playcanvas.com/engine/classes/MeshInstance.md)`[]`): An array of mesh instances.
- `name` (`string`, optional): The name of the variant, as queried by getMaterialVariants. If null,
  the variant will be reset to the default.

**Example**

```ts
// load a glb file and instantiate an entity with a render component based on it
app.assets.loadFromUrl("statue.glb", "container", (err, asset) => {
    const entity = asset.resource.instantiateRenderEntity({
        castShadows: true
    });
    app.root.addChild(entity);
    const materialVariants = asset.resource.getMaterialVariants();
    const renders = entity.findComponents("render");
    for (let i = 0; i < renders.length; i++) {
        const renderComponent = renders[i];
        asset.resource.applyMaterialVariantInstances(renderComponent.meshInstances, materialVariants[0]);
    }
});
```

### getMaterialVariants

```ts
getMaterialVariants(): string[]
```

Queries the list of available material variants.

**Returns** `string[]`: An array of variant names.

### instantiateModelEntity

```ts
instantiateModelEntity(options?: any): Entity
```

Instantiates an entity with a model component.

**Parameters**

- `options` (`any`, optional): The initialization data for the model component type
  [ModelComponent](https://api.playcanvas.com/engine/classes/ModelComponent.md).

**Returns** [`Entity`](https://api.playcanvas.com/engine/classes/Entity.md): A single entity with a model component. Model component internally
contains a hierarchy based on [GraphNode](https://api.playcanvas.com/engine/classes/GraphNode.md).

**Example**

```ts
// load a glb file and instantiate an entity with a model component based on it
app.assets.loadFromUrl("statue.glb", "container", (err, asset) => {
    const entity = asset.resource.instantiateModelEntity({
        castShadows: true
    });
    app.root.addChild(entity);
});
```

### instantiateRenderEntity

```ts
instantiateRenderEntity(options?: any): Entity
```

Instantiates an entity with a render component.

**Parameters**

- `options` (`any`, optional): The initialization data for the render component type
  [RenderComponent](https://api.playcanvas.com/engine/classes/RenderComponent.md).

**Returns** [`Entity`](https://api.playcanvas.com/engine/classes/Entity.md): A hierarchy of entities with render components on entities containing
renderable geometry.

**Example**

```ts
// load a glb file and instantiate an entity with a render component based on it
app.assets.loadFromUrl("statue.glb", "container", (err, asset) => {
    const entity = asset.resource.instantiateRenderEntity({
        castShadows: true
    });
    app.root.addChild(entity);

    // find all render components containing mesh instances, and change blend mode on their materials
    const renders = entity.findComponents("render");
    renders.forEach((render) => {
        render.meshInstances.forEach((meshInstance) => {
            meshInstance.material.blendType = BLEND_MULTIPLICATIVE;
            meshInstance.material.update();
        });
    });
});
```
