In this lesson, you will learn how to bridge the gap between abstract AI decision-making and the physical execution of movement by triggering dynamic pathfinding requests.
From Decision to Motion
Up until now, we’ve focused on the AI’s "brain"—the Perception system that identifies targets and the State machines that decide what the AI should do. However, an AI that decides to "Pursue Target" remains stationary until it actually commands its controller to calculate and follow a path.
To bridge this, we use the AI MoveTo node (or the MoveTo task in Behavior Trees). When the AI controller receives this command, it doesn’t just walk in a straight line; it asks the Navigation Mesh for a path. The pathfinder calculates a sequence of points that circumvent obstacles, ensuring your AI navigates the environment realistically rather than bumping into walls.
Implementing the Request
In a Behavior Tree, this is handled by the MoveTo node. The key is providing a Blackboard Key that stores the target location. When the AI reaches the state where it needs to move, the system sends a pathfinding query to the navigation engine.
Here is a simplified look at how you trigger this from an AI Controller via C++:
// Within your AI Controller's decision logic
void AMyAIController::MoveToTarget(AActor* TargetActor)
{
// The request triggers the pathfinder to calculate a route
FAIMoveRequest MoveRequest;
MoveRequest.SetGoalActor(TargetActor);
MoveRequest.SetAcceptanceRadius(50.0f);
MoveTo(MoveRequest);
}
Why Dynamic Requests Matter
If your game world changes—for example, if a player places a barricade in a doorway—the initial path might become blocked. By using pathfinding requests, the AI Controller continuously validates the current path. If the path becomes invalid, the AI doesn't just stop; it can trigger a new request to navigate around the new obstacle. This dynamic feedback loop is what makes your AI feel intelligent rather than scripted. Always ensure your NavMesh is set to "Dynamic" in your project settings so these requests can account for moving geometry.
Key Takeaway: AI decisions provide the "why" and "where," while pathfinding requests provide the "how," allowing your AI to navigate obstacles and complex geometry to fulfill its goals.