Why does FindPathSync not return successful path

I am trying to use the existing navigation path finding to get a list of points for my AI to travel through, I have the nav mesh generated as the regular AIMoveTo function works flawlessly, so that means it must be with my code. I have not found anything in reguards to the proper up to date way of interacting with the navigation system as I am on 5.4.1

This is the code that I have cobbled together and pathResult is always unsuccessful, it claims an error of 1, which according to documentation is just “Error”. I know for a fact that Start and End are valid locations that have worked when using AIMoveTo.

bool GetNavPoints(TArray<FNavPathPoint>& OutNavPoints, FVector Start, FVector End){
UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>(GetWorld());
if(!NavSys)
	return false;
DrawDebugPoint(GetWorld(), Start, 25, FColor::Magenta, false, 30);

FNavAgentProperties agentProp;
agentProp.AgentHeight = 100;
agentProp.AgentRadius = 30;
agentProp.bCanWalk = true;
agentProp.bCanFly = false;

FPathFindingQuery query;
query.EndLocation = End;
query.StartLocation = Start;

FPathFindingResult pathResult = NavSys->FindPathSync(agentProp, query);
if (!pathResult.IsSuccessful())
	return false;
OutNavPoints = pathResult.Path->GetPathPoints();
return true;
}

Hi there! I’ve just migrated from UE5.2 to UE5.3 and suddenly my FindPathSync returns always false (but NavMesh is Ok and character moves using MoveTo). To solve it I had to specify PathQuery.QueryFilter additionally to my previously specified parameters (seems that since EU5.3 it’s turned to null or whatever) Here is the code:

// Use the Navigation System to find the path
UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent(GetWorld());
AActor* OwnerChar = this; // Assuming this is a valid actor like a Pawn
if (!OwnerChar)
{
UE_LOG(LogTemp, Error, TEXT(“Owner is null!”));
return;
}

// Use the default query filter class
TSubclassOf QueryFilterClass = UNavigationQueryFilter::StaticClass();
FSharedConstNavQueryFilter QueryFilter = UNavigationQueryFilter::GetQueryFilter(*NavSys->GetDefaultNavDataInstance(), OwnerChar, QueryFilterClass);

// Now use QueryFilter in your pathfinding query
FPathFindingQuery PathQuery;
PathQuery.StartLocation = StartLocation;
PathQuery.EndLocation = PathDestination;
PathQuery.NavData = NavSys->GetDefaultNavDataInstance();
PathQuery.Owner = OwnerChar;
PathQuery.QueryFilter = QueryFilter;

FPathFindingResult PathResult = NavSys->FindPathSync(PathQuery);
if (PathResult.IsSuccessful())
{
UE_LOG(LogTemp, Log, TEXT(“Path successfully found!”));
}
else
{
UE_LOG(LogTemp, Warning, TEXT(“Pathfinding failed!”));
}

1 Like