> For the complete documentation index, see [llms.txt](https://docs.candy-smith.com/main/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.candy-smith.com/main/bubble-shooter-toolkit/scripts/scripts-overview/ball-spawner.md).

# Ball spawner

This method would be called when there's a need to spawn a new `Ball` in the game, such as at the start of a level or when a player makes a move that generates a new `Ball`. Use name of the prefab in parameter. Use SetPosition to put ball to the static position on the field.

Here's an example of how to use the `BallPool` to create a ball with a random color:

{% code overflow="wrap" fullWidth="false" %}

```csharp
var ball = PoolObject.GetObject("Ball 0").GetComponent<Ball>();
ColorManager.instance.GenerateColorInGame());

// set position on the field
ball.SetPosition((col,row));
```

{% endcode %}

In this case, we're creating a new ball at position (0,0) with a random color. The color is determined by passing the integer equivalent of `EBallColor.RandomColor` to the `SpawnBall` method. This enum value tells the method to assign a random color to the ball.
