Random wandering can be achieved in couple of ways, depending on which systems do you want to use.
Best (and most complex) approach is preparing behavior tree - although you have to enable them in editor preferences (menu Edit>Editor Preferences, Experimental section). You may want to check tutorial thread mentioned above, or just follow those steps:
- Create new blackboard asset (new Data Asset -> Blackboard), to store destination point: single key with KeyType set to BlackboardKeyType_Vector
- Create new behavior tree task for picking random location. This can be done either in blueprint or c++ code:
- blueprint = new blueprint asset (new Blueprint, parent class: BTTask_BlueprintBase), important: add new variable with type BlackboardKeySelector and make it public (click closed eye next to variable name, opened = public)

- c++ = new class derived from UBTTask_BlackboardBase, implement your own ExecuteTask() function
EBTNodeResult::Type UBTTask_FindLocation::ExecuteTask(class UBehaviorTreeComponent* OwnerComp, uint8* NodeMemory)
{
UNavigationSystem* NavSys = UNavigationSystem::GetCurrent(OwnerComp);
AAIController* MyAI = Cast<AAIController>(OwnerComp->GetOwner());
if (NavSys && MyAI && MyAI->GetPawn())
{
const float SearchRadius = 1000.0f;
FNavLocation RandomPt;
const bool bFound = NavSys->GetRandomPointInRadius(MyAI->GetPawn()->GetActorLocation(), SearchRadius, RandomPt);
if (bFound)
{
OwnerComp->GetBlackboardComponent()->SetValueAsVector(GetSelectedBlackboardKey(), RandomPt.Location);
return EBTNodeResult::Succeeded;
}
}
return EBTNodeResult::Failed;
}
- Create new behavior tree (new Misc>BehaviorTree), set your blackboard in root’s properties. You can start with having just a sequence composite with two nodes: Find Spot (task from step 2) and MoveTo, both accessing the same key in blackboard.
- Spawn new AI and make it run your behavior tree. Easiest way is running SpawnAI from level’s blueprint.
As I said, this is most complex way, but gives you best starting point for further modifications. Easy setup for blueprints:
- call MoveToLocation/MoveToActor function on AIController
- bind ReceiveMoveCompleted event in AIController, use it to detect reaching goal
- call GetRandomPoint/GetRandomPointInRadius functions (leave NavData and FilterClass empty) to pick random points on navmesh
Even easier setup for blueprints:
- Use “AI MoveTo” function, it should handle finish events for you
- call GetRandomPoint/GetRandomPointInRadius functions (leave NavData and FilterClass empty) to pick random points on navmesh
And finally, c++ version:
- call MoveToLocation/MoveToActor on AIController
- override OnMoveCompleted in AIController to detect reaching goal
- accessing NavigationSystem for random points was shown above
While I’m on it, let’s talk about how to influence path finding. You can define different navigation areas, with different travel or entry costs - either in blueprints or c++. Just create new blueprint/class inheriting from NavArea. I strongly suggest to keep travel cost (DefaultCost property) greater or equal to 1. Areas are usually applied by NavModifierVolume or StaticMeshes configured to be dynamic obstacles (check NavCollision property of static mesh for details).
Additionally, you may want to check two more actors: ANavLinkProxy (e.g. jump down links) and ANavigationTestingActor (path finding debug tool, including step by step display).
Hope it helps!