Instance Container

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

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, and exposes a simple API for adding, updating, querying, and removing instances at runtime or in the editor.

See also: Conversion

Instance Container UI

Properties

Prefab

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

InstanceHandles

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

LocalTransforms

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


Example

Basic runtime usage for spawning instances into a container:

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

Last updated