AI Navigation, Custom Pathing Using Nav Modifiers, Nav Area Classes, and Query Filters
Dear Community,
I’ve just released a new wiki on how to use Nav Modifiers and Query Filters!
Wiki Link
https://wiki.unrealengine./AI_Custom_Pathing,_How_To_Use_Nav_Modifiers_Query_Filters#Nav_Area_Class
**Video**
https://youtube./watch?v=xwdVQQtQa8s
Use Case: Electric Currents and 2 Types of Characters
In my example, I have two types of units.
The blue unit is immune to electricity, and does not need to path around electric currents.
The red unit bids us all a fond farewell if it passes thruogh an electric current.
So in case I can’t just block of areas that have electric currents completely from the nav mesh, or else the blue unit cannot pass through freely as it should be able to, taking a shortcut as a result.
is a case where Nav Modifiers and Query Filters really shine!
I only want to filter out certain sections of the nav mesh for the red unit, while still allowing the blue unit to pass through those areas freely.
**C++ Code**
Here's the code I used to make a BP Node that allows you to use custom Navigation Query Filters in Blueprints!
Notice the in-Editor documentation!
//.h
```
/** Move to Location with optional Query Filter!
*
* 1. Create Custon Nav Area Classes.
*
* 2. Use Nav Modifier Volumes to apply custom area class data within the level, then
*
* 3. Create Query Filters which alter/exclude those custom nav areas.
*
* 4. Can then choose to use the filters per character or even per Move To using node.
*
* <3
*
* @param FilterClass - Allows different types of units to path in different ways all the time, or path differently per Move To using node!
* @param bProjectDestinationToNavigation - Whether to attempt to find a nearby point on the nav mesh below/above/close to the supplied point. Uses the Agent's Nav Extent for the projection
* @param bStopOnOverlap - Add pawn's radius to AcceptanceRadius
* @param bCanStrafe - Set focus related flag: bAllowStrafe
* @return Whether the Pawn's AI Controller is valid and goal can be pathed to
*/
UFUNCTION(BlueprintCallable, Category = "VictoryBPLibrary|AI Move To")
static EPathFollowingRequestResult::Type Victory_AI_MoveToWithFilter(
APawn* Pawn,
const FVector& Dest,
TSubclassOf<UNavigationQueryFilter> FilterClass = NULL,
float AcceptanceRadius = 0,
bool bProjectDestinationToNavigation = false,
bool bStopOnOverlap = false,
bool bCanStrafe = false
);
```
//.cpp
```
EPathFollowingRequestResult::Type UVictoryBPFunctionLibrary::Victory_AI_MoveToWithFilter(
APawn* Pawn,
const FVector& Dest,
TSubclassOf<UNavigationQueryFilter> FilterClass ,
float AcceptanceRadius ,
bool bProjectDestinationToNavigation ,
bool bStopOnOverlap ,
bool bCanStrafe
){
if(!Pawn)
{
return EPathFollowingRequestResult::Failed;
}
AAIController* AIControl = Cast<AAIController>(Pawn->GetController());
if(!AIControl)
{
return EPathFollowingRequestResult::Failed;
}
return AIControl->MoveToLocation(
Dest,
AcceptanceRadius,
bStopOnOverlap, //bStopOnOverlap
true, //bUsePathfinding
bProjectDestinationToNavigation,
bCanStrafe, //bCanStrafe
FilterClass //<~~~
);
}
```
Enjoy!