# Instance Container

The **Instance Container** component is designed to manage large groups of instanced meshes—such as foliage, debris, or props—**without requiring individual GameObjects**.

It serializes instance transform data, integrates with the central [FloraSystem](https://flora.magneticarcade.com/scripts/system), and exposes a simple API for adding, updating, querying, and removing instances at runtime or in the editor.

See also: [Conversion](https://flora.magneticarcade.com/getting-started/conversion)

> For workflows without Unity `Terrain`, this is the primary Flora path for managing large groups of instances without individual GameObjects. See [Container Mesh Sample](https://flora.magneticarcade.com/samples/container-samples#container-mesh-sample) and [Container Prefab Sample](https://flora.magneticarcade.com/samples/container-samples#container-prefab-sample).\
> For Unity `Terrain` trees/details, use [Terrain Provider](https://flora.magneticarcade.com/scripts/terrain-provider).

<figure><img src="https://2882982566-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fyo4B7EVXffipTxnJzee6%2Fuploads%2Fgit-blob-59ac621ca9103e4815622fe80b7f8ae0ca532710%2Finstance-container-scene-01.webp?alt=media" alt="Instance Container UI"><figcaption></figcaption></figure>

***

### Properties

#### <mark style="color:yellow;">Prefab</mark>

The prefab rendered by all instances in this container.\
Changing this will **rebuild** all instances.

#### <mark style="color:yellow;">InstanceHandles</mark>

An array of runtime **instance handles**, used internally by Flora to track each instance.

#### <mark style="color:yellow;">LocalTransforms</mark>

An array of **container-space transforms** (position, rotation, scale) for each instance.

***

### Example

Basic runtime usage for spawning instances into a container:

```csharp
public class FoliageSpawner : MonoBehaviour
{
    public FloraInstanceContainer container;
    public GameObject treePrefab;

    void Start()
    {
        container.Prefab = treePrefab;

        // Spawn 100 instances in a 10x10 grid
        for (int x = 0; x < 10; x++)
        for (int z = 0; z < 10; z++)
        {
            Vector3 pos = new Vector3(x * 2f, 0, z * 2f);
            container.AddInstance(pos, Quaternion.identity, Vector3.one, Space.World);
        }
    }
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://flora.magneticarcade.com/scripts/instance-container.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
