# Following

Make a group of agents follow another agent. They form up on the leader the same way a
`SetAgentsTarget` to the leader's position would place them, and keep up with it as it moves.

```cpp
Crowd->SetAgentsFollowTarget(Squad, LeaderIndex, ECrowdToolkitFormationAnchor::NearEdge);
```

- **Anchor** works like on `SetAgentsTarget`. **Near Edge** puts the front of the group against
  the leader, on the side the group comes from; **Center** puts the leader in the middle of the
  group.
- The group uses the current **Formation → Shape**, just like a normal move order.
- The group gathers toward the leader from wherever it is, so it trails a walking leader. With
  **Near Edge** it holds its ground while the leader walks into or through it, and gathers again
  once the leader is clear; with **Center** it keeps re-centring on the leader.
- Followers don't fire `OnAgentsReachedGoal` - there is no destination to reach.

## Stopping

- `ClearAgentsFollowTarget(Squad)` - stop following; the agents settle where they are.
- Giving a follower a normal `SetAgentsTarget` also stops its follow.
- If the **leader is removed**, the followers stop where they are and
  [`OnAgentsLostFollowTarget`](./05-events.md) fires with their indices.

`GetAgentFollowTargets` returns who each agent is following (`-1` = nobody).

## Chains

Follows can be chained: A follows B, B follows C. An order that would make a loop (C follows A)
is refused and returns `false`.

## Following an actor

Only agents can be followed. To follow a player character or any other actor, spawn one
**proxy agent**, move it to the actor's location every tick with
[`SetAgentPosition`](../api_reference/01-crowd_actor.md#teleport), and have the group follow
the proxy.

The **FollowExample** map does exactly this with `BP_FollowProxyExample`: spawn one agent on
BeginPlay, teleport it to the actor every Tick, and make every spawned agent follow it.

::: tip
The proxy is a normal agent, so it shows up in queries and transforms. Put it on its own
[team](./08-teams.md) to filter it out, or skip its index when rendering.
:::
