# Spawnables

### Principle

The Spawnables component is there to provide the objects that are spawned by the different effects. The class itself is not optimized as it uses Instantiate instead of object pooling, but this is on purpose. It is not (only) because I am lazy that I took that decision, but because I assume that most people already have their implementation of object pooling and that it's better to provide something that can be plugged in your implementation rather than forcing another one.

It works pretty much how you would expect, you can give it a bunch of prefab to pick from and assign them a probability, and then it will randomly pick one of those each time you call **SpawnObject()**. This is an example of setup, which is rather self explanatory.

<figure><img src="https://2791585758-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FE8bOcbAuH0ZMX3MgiT9p%2Fuploads%2FZwIheex0oONWzNa8iAWY%2Fimage.png?alt=media&#x26;token=4437edd1-0064-4f0d-aa75-88e506407ac4" alt=""><figcaption></figcaption></figure>

If you'd go about plugging in your object pooling in there, you could just modify the class so that instead of having "ObjectToSpawn", you'd give it your object pool. Then modify the very last line of the script into whatever your object pooling is defined:

```
return Instantiate(objectToSpawn);
```

Then you'll also need some work to make sure that the object are not Destroyed in the effects you create but rather put back in the pool, I'll leave this up to you as you might probably just create your own effects.

### Notes

The **Locked** property doesn't prevent you from changing the probability, but prevents the code from doing so. The code is always going to try to keep the probabilities adding up to 1, but you can break that if you move around too much the locked values.&#x20;

However even if you get a sum of probability above 1, it will be normalized by the **SpawnObject()** method so there shouldn't be any unexpected behavior, but it's good that you know about it.


---

# 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://ffactory-1.gitbook.io/procedurally-propagating-paths/fundamentals/reference/spawnables.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.
