ANavMeshBoundsVolume Linker Error

I am on section 5 lecture 320.

When I try to compile the code using Unreal engine 4.21.1, I get this linker error
Severity Code Description Project File Line Suppression State
Error LNK2019 unresolved external symbol “__declspec(dllimport) private: static class UClass * __cdecl ANavMeshBoundsVolume::GetPrivateStaticClass(void)” (_imp?GetPrivateStaticClass@ANavMeshBoundsVolume@@CAPEAVUClass@@XZ) referenced in function “public: void __cdecl AInfiniteTerrainGameMode::PopulateBoundsVolumePool(void)” (?PopulateBoundsVolumePool@AInfiniteTerrainGameMode@@QEAAXXZ) TestingGrounds Documents\Unreal Projects\TestingGrounds\Intermediate\ProjectFiles\InfiniteTerrainGameMode.cpp.obj 1

Here is the list of things I have tried numerous times

  1. Delete binary, intermediate and saved and .sln file, regenerate everything.
  2. Adding this line to my TestingGrounds.target.cs and TestingGroundsEditor.Target.cs
    ExtraModuleNames.AddRange(new string { “TestingGrounds”, “NavigationSystem”,“AIModule”, “Navmesh” });
  3. Re parenting my game mode class to the testing grounds one, then deleting the InfiniteTerrainGameMode c++ file and header, regenerating game files
  4. Adding various header files, include Engine.h just to try to get it to work

I have found the actual Function that is causing the problem

void AInfiniteTerrainGameMode::PopulateBoundsVolumePool()
{
        // The line below is causing the problem
	auto VolumeIterator = TActorIterator<ANavMeshBoundsVolume>(GetWorld());
	//TActorIterator<ANavMeshBoundsVolume> VolumeIterator = TActorIterator<ANavMeshBoundsVolume *>(GetWorld());
	TArray<ANavMeshBoundsVolume> *NavMesh = NULL;
	/*
	while (VolumeIterator)
	{
		AddToPool(*VolumeIterator);
		++VolumeIterator;
	}
	*/
}

comment out that line and it compiles fine.
Tried using this in its place
TArray<AActor *> found;
UGameplayStatics::GetAllActorsOfClass(GetWorld(),ANavMeshBoundsVolume::StaticClass(), found);

Got the exact same linker error.

I tried adding this to my InfiniteTerrainGameMode.cpp file and override in the header
void AInfiniteTerrainGameMode::PostRegisterAllComponents()
{
Super::PostRegisterAllComponents();
}

Here are both files in their entirety
// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

#include “TestingGroundsGameMode.h”
#include “NavigationSystem/Public/NavMesh/NavMeshBoundsVolume.h”
#include “Classes/AISystem.h”
#include “InfiniteTerrainGameMode.generated.h”

/**
*
*/
UCLASS()
class TESTINGGROUNDS_API AInfiniteTerrainGameMode : public ATestingGroundsGameMode
{
GENERATED_BODY()

public:
AInfiniteTerrainGameMode();

//UFUNCTION(BlueprintCallable, Category = "Bounds Pool")
void PopulateBoundsVolumePool();
void PostRegisterAllComponents() override;

protected:
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = “Pool”)
class UActorPool* NavMeshBoundsVolumePool;

private:
void AddToPool(ANavMeshBoundsVolume *VolumeToAdd);
};

cpp file
// Fill out your copyright notice in the Description page of Project Settings.

#include “InfiniteTerrainGameMode.h”
#include “TestingGrounds.h”
#include “NavigationSystem/Public/NavMesh/NavMeshBoundsVolume.h”
#include “Classes/AISystem.h”
#include “EngineUtils.h”
#include “ActorPool.h”
#include “GameFramework/Actor.h”
#include “Kismet/GameplayStatics.h”

AInfiniteTerrainGameMode::AInfiniteTerrainGameMode()
{
NavMeshBoundsVolumePool = CreateDefaultSubobject(FName(“Nav Mesh Bounds Volume Pool”));
}

void AInfiniteTerrainGameMode::PopulateBoundsVolumePool()
{
//TArray<AActor *> found;
//UGameplayStatics::GetAllActorsOfClass(GetWorld(),ANavMeshBoundsVolume::StaticClass(), found);
auto VolumeIterator = TActorIterator(GetWorld());
//TActorIterator VolumeIterator = TActorIterator<ANavMeshBoundsVolume *>(GetWorld());
//TArray NavMesh = NULL;
/

while (VolumeIterator)
{
AddToPool(*VolumeIterator);
++VolumeIterator;
}
*/
}

void AInfiniteTerrainGameMode::AddToPool(ANavMeshBoundsVolume *VolumeToAdd)
{
NavMeshBoundsVolumePool->Add(VolumeToAdd);
}

void AInfiniteTerrainGameMode::PostRegisterAllComponents()
{
Super::PostRegisterAllComponents();
}

Please help, I am unable to continue the course without this error being resolved. Oh, I also tried copying and pasting both the cpp and header files from github for testing grounds, which produced the exact same error.

2 Likes

I am also having this issue in UE 4.22.2

I am at the point of using the AddToPool stub to UE_Log the name of each ANavMeshMolume in the VolumeIterator.

At this stage I am also getting the error:

I have found that it compiles and works correctly using TActorIterator, although this shows all volumes, not just NavMeshVolumes. But the issue seems to not only be with using TActorIterator with ANavMeshVolume, as just adding “ANavMeshBoundsVolume myVolume;” alone in my .cpp produces the error:

Error	LNK2019	unresolved external symbol "__declspec(dllimport) public: virtual __cdecl ANavMeshBoundsVolume::~ANavMeshBoundsVolume(void)" (__imp_??1ANavMeshBoundsVolume@@UEAA@XZ) referenced in function "public: void __cdecl AInfiniteTerrainGameMode::PopulateBoundsVolumePool(void)" (?PopulateBoundsVolumePool@AInfiniteTerrainGameMode@@QEAAXXZ)	S05_TestingGrounds	F:\Documents\Unreal Projects\Udemy Courses\S05_TestingGrounds\Intermediate\ProjectFiles\InfiniteTerrainGameMode.cpp.obj	1	

I would really appreciate it if anyone could share how they got past this problem.

SOLVED:
I had the same issue in UE 4.22. The thing is that in 4.20 they moved the logic of navigation systems from Engine to a specific module called “NavigationSystem”. You just need to add the new module to your Build.cs file. It should look like this:

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "HeadMountedDisplay", "AIModule", "GameplayTasks", "NavigationSystem" });

Be aware that VS and UE4 editor can go crazy and give you new linking errors depending on how you change the modules, or at least that’s what happened to me. Initially I just added the module in the non-compiling code state, thinking that it would compile fine with the new module included, but it threw a new lnk2001 error. When I removed the module back the error persisted, even cleaning the temp folders and rebuilding, and wasn’t able to compile at all.

I had to go back in version control to a compilable state, before the first linking error appeared, add the module, and then add the breaking code related to Nav Mesh Volumes. Now it’s working fine.

Hope this helps someone.

3 Likes

Lifesaver! Thank you so much for sharing this. Unreal is powerful, but “those details between the lines” sucks.

I’m taking the archived course and I want to finish it before begin the new course. Repetition makes perfection, they say.

Privacy & Terms