> 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/getneighbours.md).

# GetNeighbours

This method allows you to find and retrieve the neighbors of a particular `Ball` in your game. You can specify both the type of `Ball` you are interested in and a condition to further filter these neighbouring balls.

**Syntax:**

```csharp
var filteredNeighbours = LevelUtils.GetNeighbours<T>(Ball ball, Func<T, bool> filter);
```

**Parameters:**

* `T` : The type of the `Ball` that you want to find among the neighbours. This could be any class that derives from the `Ball` base class (like `ColorBall` for instance).
* `ball` : The `Ball` whose neighbours you want to find.
* `filter` : A `Func<T, bool>` that represents the condition to further filter the neighbours. This is a function that takes a `Ball` of type `T` and returns a boolean. If the function returns `true` for a specific `Ball`, then that `Ball` will be included in the returned array of neighbours.

**Example:**

```csharp
var filteredNeighbours = LevelUtils.GetNeighbours<ColorBall>(someBall, ball => ball.GetColor() == targetColor);
```

In this example, `GetNeighbours` is called to find all neighboring `ColorBall`s of `someBall` that have the same color as `targetColor`. The method returns an array of these `ColorBall`s.

Here, `ball => ball.GetColor() == targetColor` is a lambda expression that represents the `filter` function. It checks if the color of a `ColorBall` is the same as `targetColor`.

This method is powerful because it allows you to customize the condition for filtering neighbours, resulting in more flexibility when designing game mechanics. For example, you could easily find all `ColorBall`s of a certain color, or `BombBall`s that are about to explode, etc.
