# Runtime Samples

## Fish Boids

The Fish Boids scene demonstrates runtime-driven instance animation at high counts using Flora + jobs.

<figure><img src="https://2882982566-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fyo4B7EVXffipTxnJzee6%2Fuploads%2Fgit-blob-6ea8374ef6916805c384662f4ef4b84db7762c47%2Ffish-boids-motion-vectors.webp?alt=media" alt=""><figcaption></figcaption></figure>

### Scene Path

`Samples~/Examples/Fish/Scenes/FishBoidsSample.unity`

### What This Demonstrates

* Runtime creation and ownership of many instances
* Job-based transform simulation
* Batch update upload into Flora runtime

### APIs Exercised

* `FloraSystem.GetOrCreate()`
* `CreateInstances(...)`
* `ScheduleUpdateInstanceWorldTransforms(...)`
* `DestroyInstances(...)`

### Run and Verify

1. Open `FishBoidsSample` and press Play.
2. Confirm fish schools animate continuously.
3. Watch frame stability while instance counts are high.

**Expected result:** fish move smoothly as Flora instances without per-fish scene GameObjects for rendering.

### Common Failure Checks

* No fish visible: ensure Flora is active and sample objects enabled.
* Errors on disable: verify job dependencies complete before destroy/dispose.
* Motion vector artifacts: check runtime/scene motion-vector settings.

### Core Classes

#### FishSchool

```csharp
NativeArray<FloraInstanceTransform> m_Transforms;
NativeArray<FloraInstanceHandle> m_InstanceHandles;
JobHandle m_Dependency;

void OnEnable()
{
    m_Transforms = new NativeArray<FloraInstanceTransform>(SpawnCount, Allocator.Persistent);
    m_InstanceHandles = new NativeArray<FloraInstanceHandle>(SpawnCount, Allocator.Persistent);

    FloraSystem.GetOrCreate().CreateInstances(Prefab, gameObject, m_InstanceHandles, m_Transforms);
}

void OnDisable()
{
    m_Dependency.Complete();
    FloraSystem.Instance?.DestroyInstances(m_InstanceHandles);

    m_Transforms.Dispose();
    m_InstanceHandles.Dispose();
}
```


---

# 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/samples/runtime-samples.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.
