Get Random Reachable Point In Radius from C++, but refuses to compile?

I’m absolutely struggling to get this to work. I don’t know what I’m missing here. For context I’m in Notepad++ because Visual Studio makes me want to walk into traffic. So it’s difficulty to check what headers to include. Below is basically what I have, but it just refuses to compiled.

#include "TraceAttacks/Public/TraceAttackHelpers.h"
#include "GameFramework/WorldSettings.h"
#include "CollisionShape.h"
#include "CollisionQueryParams.h"
#include "DrawDebugHelpers.h"
#include "KismetTraceUtils.h"
#include "Kismet/KismetMathLibrary.h"
#include "Components/SkeletalMeshComponent.h"
#include "NavigationSystem.h"

FVector UTraceAttackHelpers::GetRandomLocation( UObject* WorldContextObject, AActor* Actor, float Radius )
{
	if ( ! IsValid( Actor ) ) {
		return FVector::ZeroVector;
	}

	if ( ! IsValid( WorldContextObject ) ) {
		return FVector::ZeroVector;
	}

	UWorld* World = WorldContextObject->GetWorld();

	if ( ! IsValid( World ) ) {
		return FVector::ZeroVector;
	}

	FVector Origin = Actor->GetActorLocation();
	FNavLocation RandomPoint( Origin );

	// this is erroring for some reason
	UNavigationSystemV1* NavSys = FNavigationSystem::GetCurrent<UNavigationSystemV1>( World );

	if ( ! NavSys ) {
		return Actor->GetActorLocation();
	}

	if ( ! NavSys->GetRandomReachablePointInRadius( Origin, Radius, RandomPoint ) ) {
		return Actor->GetActorLocation();
	}

	return RandomPoint.Location;
}

Below is the errors it’s spitting out.

Module.TraceAttacks.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) private: static class UClass * __cdecl UNavigationSystemV1::GetPrivateStaticClass(void)" (__imp_?GetPrivateStaticClass@UNavigationSystemV1@@CAPEAVUClass@@XZ) referenced in function "public: static struct UE::Math::TVector<double> __cdecl UTraceAttackHelpers::GetRandomLocation(class UObject *,class AActor *,float)" (?GetRandomLocation@UTraceAttackHelpers@@SA?AU?$TVector@N@Math@UE@@PEAVUObject@@PEAVAActor@@M@Z)
  Hint on symbols that are defined and could potentially match:
    "__declspec(dllimport) private: static class UClass * __cdecl UBlueprintAsyncActionBase::GetPrivateStaticClass(void)" (__imp_?GetPrivateStaticClass@UBlueprintAsyncActionBase@@CAPEAVUClass@@XZ)
    "__declspec(dllimport) private: static class UClass * __cdecl UBlueprintFunctionLibrary::GetPrivateStaticClass(void)" (__imp_?GetPrivateStaticClass@UBlueprintFunctionLibrary@@CAPEAVUClass@@XZ)
    "__declspec(dllimport) private: static class UClass * __cdecl UMeshComponent::GetPrivateStaticClass(void)" (__imp_?GetPrivateStaticClass@UMeshComponent@@CAPEAVUClass@@XZ)
    "__declspec(dllimport) private: static class UClass * __cdecl UObject::GetPrivateStaticClass(void)" (__imp_?GetPrivateStaticClass@UObject@@CAPEAVUClass@@XZ)
    "__declspec(dllimport) private: static class UClass * __cdecl USkeletalMeshComponent::GetPrivateStaticClass(void)" (__imp_?GetPrivateStaticClass@USkeletalMeshComponent@@CAPEAVUClass@@XZ)

Anyone have any suggestions? It compiles if I comment out the GetRandomReachablePointInRadius and FNavigationSystem::GetCurrent calls.

This is a linker error: it looks like there is a missing module in your project’s Build.cs file

Probably the “NavigationSystem” module.

Try to add it in the Build.cs file (PublicDependencyModuleNames section)

1 Like

This is inside of an engine plugin. So I assume I need to just add it to PrivateDependencyModuleNames?

Edit: Yup, that did the trick. Added “NavigationSystem” to PrivateDependencyModuleNames in my engine plugins Build.cs. Thanks!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.