Making AI characters move naturally and efficiently in-game is very important for enhancing game immersion. However, when setting up AI pathfinding in Unreal Engine, have you faced problems like "AI bumps into walls and won't move" or "performance degrades on large maps"?
Many of these problems stem from insufficient Navigation Mesh (NavMesh) setup and optimization in Unreal Engine. This article thoroughly explains everything from basic NavMesh setup to optimization techniques for maximizing performance, and practical AI movement control using Blueprint and C++, for Unreal Engine beginners to intermediate developers.
NavMesh Bounds Volume Setup
NavMesh is a data structure indicating areas where AI can move. In Unreal Engine, a special volume called NavMesh Bounds Volume is used to generate this NavMesh.
Placing NavMesh Bounds Volume
- Placement: Drag and drop
NavMesh Bounds Volumefrom thePlace Actorspanel into the scene. - Range Setting: Adjust the placed volume's size and position to cover all areas where AI will move.
- Verification: Press P key in the editor to display NavMesh-generated areas in green. Green areas are where AI can move.
💡 Common Mistake: If NavMesh Bounds Volume is too small or floating above the ground, NavMesh won't generate correctly. Verify that the volume's center is on the ground and completely encompasses the entire movement area.
Basic Adjustments in Project Settings
NavMesh generation precision and behavior can be adjusted in the Navigation Mesh section of Project Settings.
| Setting | Description | Best Practice |
|---|---|---|
| Cell Size | NavMesh grid size. Smaller = higher precision, but increased generation cost and memory. | Usually default is sufficient. Reduce for fine movement needs. ※ |
| Cell Height | NavMesh cell height. | Default (25.0) is sufficient. |
| Agent Radius | AI character radius. Distance from walls and obstacles is calculated based on this radius. | Match to AI character's Capsule Component radius. |
| Agent Height | AI character height. | Match to AI character's Capsule Component height. |
| Agent Max Slope | Maximum slope angle (degrees) AI can climb. | Default (44 degrees) is sufficient. Increase to climb steep slopes. |
| Agent Max Step Height | Step height AI can step over. | Set considering character leg length. Default is 35.0. |
※ Cell Size default value may vary by engine version. Please verify in your version.
Adjusting these settings to match AI character size is the most basic NavMesh optimization.
Troubleshooting When AI Can't Move
If AI can't move on NavMesh, check the following:
- Agent Radius/Height: If smaller than character, it hits walls; if too large, can't pass through narrow passages.
- Agent Max Slope: If unable to climb slopes, this value may be the cause.
- Agent Max Step Height: If unable to climb steps, adjust this value.
NavMesh Optimization Techniques
In large maps or dynamic environments, NavMesh generation and updates can become performance bottlenecks. Optimize with the following settings.
Using Runtime Generation
The Runtime Generation setting in Project Settings > Navigation Mesh > Runtime category is one of the most impactful elements on performance.
| Setting Value | Description | Recommended Situation |
|---|---|---|
| Static | Build NavMesh once in editor, no runtime updates. | Most static levels. Best performance. |
| Dynamic Modifiers Only | After editor build, only reflects changes from Nav Mesh Modifier Volume, etc. at runtime. | Limited dynamic elements like destructible objects or opening doors. |
| Dynamic | Constantly updates NavMesh at runtime. | Completely dynamic environments (e.g., voxel-based games). Most expensive. |
🚀 Optimization Hint: Choose Static or Dynamic Modifiers Only whenever possible.
Dynamicis very expensive, so only consider using it when truly necessary.
Using Nav Mesh Modifier Volume
Use Nav Mesh Modifier Volume when you want to change NavMesh behavior only in specific areas.
- Changing Area Class: Make specific regions impassable or assign different area classes to affect pathfinding.
- Changing Cost: Locally increase pathfinding cost for specific ground (e.g., swamp) to make AI avoid it.
💡 About Dynamic NavMesh Updates
Nav Mesh Modifier Volume is mainly for modifying area attributes (cost, passability). To reflect new navigable areas like holes in destroyed walls in NavMesh, you need to set
Runtime GenerationtoDynamicorDynamic Modifiers Only. Modifier Volume alone won't "add" new NavMesh regions.
AI Movement Control Implementation
Once NavMesh is correctly configured, next is actually moving AI characters.
AI Movement in Blueprint (AI MoveTo Node)
The simplest and most common method is using the AI MoveTo node.
// AI Controller Blueprint
// Event: Move to TargetLocation
Sequence
-> AI MoveTo (Target Actor: None, Destination: TargetLocation, Target: Self)
-> On Success (processing when movement completes)
-> On Fail (processing when movement fails)
This node internally uses NavMesh to automatically calculate the optimal path and moves the AI character to the destination.
AI Movement in C++ (AAIController::MoveToLocation)
For more detailed control in C++, use the AAIController class's MoveToLocation function.
// MyAIController.cpp
#include "AIController.h"
#include "NavigationSystem.h"
void AMyAIController::MoveToTarget(const FVector& TargetLocation)
{
// Check if NavMesh exists
if (UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld()))
{
// Execute pathfinding and movement
FAIMoveRequest MoveRequest;
MoveRequest.SetGoalLocation(TargetLocation);
MoveRequest.SetAcceptanceRadius(10.0f); // Tolerance for considering destination reached
FNavPathSharedPtr NavPath;
MoveTo(MoveRequest, &NavPath);
}
}
Using C++ enables advanced customization like callback processing on movement success/failure, or dynamically changing paths during movement.
Smart AI Checklist
NavMesh setup and optimization directly affects both AI behavior and game performance.
- NavMesh Bounds Volume Verification: Does it cover the entire AI movement range? Did you verify the green area with P key?
- Agent Settings Adjustment: Did you adjust
Project Settingsto match AI character size (Radius/Height)? - Runtime Generation Optimization: For static levels, did you select
StaticorDynamic Modifiers Onlyto reduce unnecessary runtime costs? - Movement Control Implementation: Are you correctly moving AI using Blueprint's
AI MoveToor C++'sAAIController::MoveTo?
Following these steps will enable your Unreal Engine project's AI characters to move smarter, smoother, and without compromising performance.