> For the complete documentation index, see [llms.txt](https://flora.magneticarcade.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://flora.magneticarcade.com/scripts/instance-container.md).

# Instance Container

A serialized collection of instances that do not require individual GameObjects.

An **Instance Container** stores many instance transforms without individual GameObjects. Use it for foliage, debris, or props outside Unity `Terrain`.

See [Conversion](/getting-started/conversion.md) and [Container Samples](/samples/container-samples.md).

> For Unity `Terrain` trees and details, use [Terrain Provider](/scripts/terrain-provider.md).

<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

### `Prefab`

The prefab rendered by all instances in this container. Changing it rebuilds every instance and invalidates the previous runtime handles.

### `InstanceHandles`

Runtime handles for the container's instances.

### `LocalTransforms`

Container-space position, rotation, and scale. Moving the container moves all instances.

### `StaticSpatialCacheMode`

Controls [Static Spatial Caching](/rendering/static-spatial-caching.md). Caching requires a Static GameObject, an assigned prefab, at least one instance, and the project setting.

***

## Example

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

    void Start()
    {
        container.Prefab = treePrefab;

        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);
        }
    }
}
```

Instance changes invalidate cached spatial data. Save the scene or rebuild the cache before profiling scene loading.
