How do you get a Navigation path in UE4 4.20 in C++?

I’m currently trying to figure out how to get a Navigation path for my pawn in C++.The way I’ve seen people get the path is by using GetWorld()->GetNavigationSystem()->FindPathToLocationSynchronously(). But, in UE4 4.2, GetWorld()->GetNavigationSystem() returns a NavigationSystemBase which doesn’t have the find path functionality. Does anyone know how I can find a path in 4.2 in c++?

Also the documentation online is out of date for the include for NavigationSystem.h, its now located in Runtime/NavigationSystem/Public/NavigationSystem.h

Any help would be appreciated!

1 Like

I think I figured it out.

include “Runtime/NavigationSystem/Public/NavigationSystem.h”

then

UNavigationSystemV1* navSys = UNavigationSystemV1::GetCurrent(GetWorld());
UNavigationPath* path = navSys->FindPathToLocationSynchronously()

Just kidding, in 4.2 you have to add “NavigationSystem” to your projects Build.cs

and to get the path finding system and nav points

UNavigationSystemV1* navSys = FNavigationSystem::GetCurrent(GetWorld());

UNavigationPath* path = navSys->FindPathToLocationSynchronously(GetWorld(), GetPawn()->GetActorLocation(), position, NULL);

1 Like

So my first answer worked on my work project and my second answer worked when I was in the UE4 Advanced Car template project. I’m pretty sure they are both engine version 4.20, so idk whats up with that.

Wow thanks for the tip about adding the navigation system to the build.cs file. Don’t know how you figured it out but that worked out for me.
I was already pulling my hair out trying to figure out why the linker couldn’t find the definition for FindPathToLocationSynchronously().

Wow thanks for the tip about adding the navigation system to the build.cs file. Don’t know how you figured it out but that worked out for me.
I was already pulling my hair out trying to figure out why the linker couldn’t find the definition for FindPathToLocationSynchronously().