> For the complete documentation index, see [llms.txt](https://malbersanimations.gitbook.io/animal-controller/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://malbersanimations.gitbook.io/animal-controller/scriptable-architecture/scriptables/runtime-gameobjects.md).

# Runtime GameObjects

Last updated AC v1.5.3

## Overview

Runtime GameObjects are a great way to store, categorize, and identify groups of GameObjects during runtime.

{% embed url="<https://youtu.be/P6-VktwCWrA>" %}

This feature uses 3 components:

* The Runtime GameObject Scriptable Asset
* The Add Runtime GameObject component
* The Get Runtime GameObject component

## Runtime GameObject Asset

This asset stores all the GameObjects that are set at runtime.

![](https://963537199-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-Lzhr1XSMzMqNXjRnNlb%2F-MaR0qvCi2cXzx-7lxzc%2F-MaR3Dyb_WXUSqI1NdEx%2Fimage.png?alt=media\&token=2358cfa5-b3e2-428e-9447-1a456b357a25)

## Add Runtime GameObjects

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2F2CsPYlzPv1AIyl86EdXJ%2Fimage.png?alt=media&#x26;token=c7938e68-4dd3-4404-85f6-888a81f568a3" alt=""><figcaption></figcaption></figure>

When this component is added to a GameObject, it adds that GameObject to the given runtime set on enable.

### Parameters

#### Collection

Runtime set used to add the GameObject that has the component.

## Get Runtime GameObjects

<figure><img src="https://963537199-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-Lzhr1XSMzMqNXjRnNlb%2Fuploads%2FzSYuPV1HpPLieDmOMyJj%2Fimage.png?alt=media&#x26;token=adcdcce7-cf08-417d-93be-6c293fd24368" alt=""><figcaption></figcaption></figure>

When this component is added to a GameObject, it finds an item in a Runtime Object collection set and uses Unity Events to connect the result to any other component.

### Parameters

#### Collection

The Runtime GameObject asset to search in. It is a required field.

#### Evaluate On Enable

When it is on, the component searches the Collection automatically on enable. Turn it off to search only when something calls `Evaluate()`.

#### Delay

Time in seconds to wait before the search runs. With a delay of zero the search still waits one frame, so every other component has finished enabling.

#### Type

How the item is chosen from the Collection.

* `First`: the first item on the list.
* `Random`: a random item. This is the default.
* `Index`: the item at the Index value.
* `ByName`: the first item whose name matches the Name value.
* `Closest`: the item closest to the GameObject holding this component.

#### Index

Position of the item to get. It is only shown when the Type is `Index`.

#### Name

Name of the item to get. It is only shown when the Type is `ByName`.

### Events

#### Raise\<GameObject>

Invoked when the search finishes. Sends the item that was found, or null when the Collection is empty or nothing matched.

#### On Item Added\<GameObject>

Invoked when any GameObject is added to the Collection while this component is enabled. Sends the GameObject that was added.

#### On Item Removed\<GameObject>

Invoked when any GameObject is removed from the Collection while this component is enabled. Sends the GameObject that was removed.

### Reactions

#### Raise Reaction

Reacts on the item found by the search, right after the Raise event.

#### On Item Added Reaction

Reacts on the GameObject that was added to the Collection.

#### On Item Removed Reaction

Reacts on the GameObject that was removed from the Collection.

### Methods

#### `void Evaluate()`

Runs the search using the current Type, honoring the Delay. Call it from a Unity Event or from code to refresh the result.

#### `void SetCollection(RuntimeGameObjects col)`

Swaps the Collection at runtime. It does not search by itself, so call `Evaluate()` afterwards.
