Course contentsShow
← Unreal Engine Game Development
Lesson 409 of 8806. AI, Navigation, and Decision MakingFree lesson

Setting Up Dynamic Obstacle Avoidance

Learners will integrate RVO or Detour Crowd avoidance to prevent AI agents from colliding with each other or moving obstacles.

In this lesson, you will learn how to move beyond basic pathfinding by implementing Detour Crowd Avoidance to ensure your AI agents navigate around each other and moving hazards in real-time.

The Problem: NavMesh Limitations

While your NavMesh provides a static map for pathfinding, it doesn't account for other agents or dynamic obstacles moving through the world. If two AI agents move toward each other, they will simply walk through each other’s capsules unless you enable specialized avoidance logic. This is where the Detour Crowd system comes in.

Implementing Detour Crowd

To enable this, we use the DetourCrowdAIController. Instead of using a standard AIController, you swap the parent class of your controller to inherit from DetourCrowdAIController.

Once configured, the agent becomes part of a "Crowd Manager" that performs local steering adjustments. Instead of recalculating the entire path (which is expensive), the agent performs a small, per-frame velocity adjustment to veer away from nearby entities.

Configuration Best Practices

You can fine-tune this behavior within your AI Controller’s Path Following Component or by adjusting the Crowd Manager settings in your project:

  1. Avoidance Quality: This determines how complex the math is for calculating paths around obstacles. Keep this at "Medium" or "High" for player-facing AI.
  2. Obstacle Avoidance Type: You can select between different profiles (e.g., "Good" or "High"). Use "High" for agents that need precise spacing, but be aware it carries a higher CPU cost.

If you are using a standard CharacterMovementComponent, ensure that Use RVO Avoidance is checked if you prefer a lighter-weight (but less sophisticated) alternative to the full Detour system. However, for most production-level AI, Detour Crowd is the industry standard.

To visualize what is happening under the hood during development, use the console command: ai.debug.navigation 1 This will show you the "avoidance cylinders" the agents are using to detect each other.

Key Takeaway: Detour Crowd Avoidance dynamically adjusts an AI’s velocity to navigate around moving entities without needing to trigger expensive global pathfinding recalculations.