FindPathSync Finds only 2 points

I am trying to find the turn points of an actor’s path:


I use MoveToLocation function to move my actor to it’s target by avoiding obstacles. I have been wondering how can I get the turn points of the path. I am using FindPathSync to find the actor’s path and find all the vectors which build it:

				FPathFindingQuery Query;
				FAIMoveRequest MoveReq(AVikingKingPlayerController::mouseHit.ImpactPoint);
				MoveReq.SetUsePathfinding(true);

				bool bValidQuery = ((AAIController*)GetController())->PreparePathfinding(MoveReq, Query);

				if (bValidQuery)
				{
					const FNavAgentProperties navAgetProp = FNavAgentProperties(34, 176);

					UNavigationSystem* NavSys = UNavigationSystem::GetCurrent(GetWorld());
					FPathFindingResult PathResult;
					TArray<FVector> Result;


					PathResult = NavSys->FindPathSync(navAgetProp, Query);

					for (FNavPathPoint point : PathResult.Path->GetPathPoints())
					{
						Result.Add(point.Location);
					}
				}

Despite there is an obstacle in his way, and as I can see he arounds it, Result contains only 2 vectors - start and end vector. What do I do wrong? how can I get the turn points?

When you’re using detour avoidance the path found for AI is not being string-pulled since it’s not required for crowd agents. The path contains the full navigation corridor information though.

If you need a string-pulled path you can always call PerformStringPulling on the path instance.

Cheers,

–mieszko

I have been noticed that PerformStringPulling belongs to :

I do not have any object that derives from , how can I use this function? correct me if I am wrong.
Also, this functio get 2 vectors and returns nothing. How do I suppose to use it?

Hey, After research I think I know how to use PerformStringPulling but I still can figure out what can I use to get PerformStringPulling.

You need to call CastPath() on your FNavigationPath instance.

Thank you it works great with NavMesh!
Is it possible to get it work with AIController UCrowdFollowingComponent? My characters avoid each other with this component and the code does not seem to “know” this component.

Can you please share how you do the PerformStringPulling function

Just ran into this issue, so i’ll leave the code here for posterity:

FNavigationPath* Path = PathFollowing->GetPath().Get();

const FVector Start = Path->GetStartLocation();
const FVector End = Path->GetDestinationLocation();

* NavMeshPath = Path->CastPath<>();
	
NavMeshPath->PerformStringPulling(Start, End);

TArray< FNavPathPoint> PathPoints = NavMeshPath->GetPathPoints();
1 Like

Sorry for reviving this old topic, but it’s the closest one I’ve seen related to my issue and what I want to achieve.

So, basically I’m using the Detour Crowd AI Component and I’m only getting two points from the Get Path Points.
I’m trying to use the PerformStringPulling but following your code, @xlar8or, I’ve been unable to.

I’m trying to do it creating a function on my AI Controller class

ABaseEnemy_AIC : public AAIController

.h

UFUNCTION(BlueprintCallable, BlueprintPure)
TArray< FNavPathPoint> ReturnPathPoints();

.cpp

TArray ReturnPathPoints()
{
FNavigationPath* Path = PathFollowing->GetPath().Get();

    const FVector Start = Path->GetStartLocation();
    const FVector End = Path->GetDestinationLocation();
  • NavMeshPath = Path->CastPath<>();

NavMeshPath->PerformStringPulling(Start, End);

return NavMeshPath->GetPathPoints();
}

First problem is, there’s no reference to anything called PathFollowing so I tried changing it for GetPathFollowingComponent()
Also noticed that “* NavMeshPath” is giving an error which seems to be solved just by adding the "include “NavMesh/NavMeshPath.h” at the top of the .h file
But when hitting compile I get

“Unrecognized type ‘FNavPathPoint’ - type must be a UCLASS, USTRUCT or UENUM”

Which I found no solution to.

I also tried to change the return type of the function to FVector and then doing a for loop in the fuction to get just the location from every PathPoint (fom the NavMeshPath->GetPathPoints()) but then another error is thrown:

unresolved external symbol "__declspec(dllimport) public: struct FVector __cdecl FNavigationPath::GetStartLocation(void)const " (_imp?GetStartLocation@FNavigationPath@@QEBA?AUFVector@@anonymous_user_9674a66c) referenced in function "protected: class TArray<struct FVector,class TSizedDefaultAllocator<32>…
unresolved external symbol “__declspec(dllimport) public: void __cdecl ::PerformStringPulling(struct FVector const &,struct FVector const &)” (_imp?PerformStringPulling@@@QEAAXAEBUFVector@@anonymous_user_f2147170@Z) referenced in function "protected: class TArray<struct FVector,class TSizedDefaultAllocator<32>…
unresolved external symbol “__declspec(dllimport) public: static struct FNavPathType const ::Type” (_imp?Type@@@2UFNavPathType@@anonymous_user_31e84eb0) referenced in function "protected: class TArray<struct FVector,class TSizedDefaultAllocator<32>…

Those I cannot find anything related to it on internet.
As you can see I’m pretty new to this stuff, because probably I’m missing the easiest part of it.
Please, help me.

Hey there, you are probably missing the NavigationSystem module on the PublicDependencyModuleNames in your project’s Build.cs, that’s why you are getting those linking errors. Hope that helps :slight_smile:

Thanks for the answer!
I already tried adding NavigationSystem module to the Build.cs file, it then compiled but getting a fatal error crash the moment the function is executed, referencing to “Path->GetStartLocation();”

Then that means that either Path or PathFollowing is nullptr. You need to debug to see which one is it. Make sure that Path Following is being properly initialized with:

UPathFollowingComponent* PathFollowing = AIController->GetPathFollowingComponent();

Yeah, I finally found the solution yesterday and it was that path was not valid for the first few frames, but after that it’s finally working. Thanks!
It’s a shame that even with the PerformStringPulling executed, using IsPartial() is still broken and always returning false.
The only option to get that working is to stop using detour avoidance it seems :confused:

I haven’t used Detour avoidance in a bit so not sure about that. Have you tried RVO avoidance or that doesn’t work for what you need?

Yeah, I tried RVO avoidance as well, but the results aren’t as accurate as the Detour ones.