error:LNK2001 within UBTService class

So I have been working on translating some blueprints into c++ and everything works fine untill I added a BTService called BTService_SenseCheck.

Severity Code Description Project File Line Suppression State Error LNK2001 unresolved external symbol “public: virtual void __cdecl IGameplayTaskOwnerInterface::OnGameplayTaskActivated(class UGameplayTask &)” (?OnGameplayTaskActivated@IGameplayTaskOwnerInterface@@UEAAXAEAVUGameplayTask@@@Z) C:\Users\Desktop\\Intermediate\ProjectFiles.generated.cpp.obj 1

Severity Code Description Project File Line Suppression State Error LNK2001 unresolved external symbol “public: virtual void __cdecl IGameplayTaskOwnerInterface::OnGameplayTaskActivated(class UGameplayTask &)” (?OnGameplayTaskActivated@IGameplayTaskOwnerInterface@@UEAAXAEAVUGameplayTask@@@Z) C:\Users\Desktop\\Intermediate\ProjectFiles\BTService_SenseCheck.cpp.obj 1

Severity Code Description Project File Line Suppression State Error LNK2001 unresolved external symbol “public: virtual void __cdecl IGameplayTaskOwnerInterface::OnGameplayTaskDeactivated(class UGameplayTask &)” (?OnGameplayTaskDeactivated@IGameplayTaskOwnerInterface@@UEAAXAEAVUGameplayTask@@@Z) C:\Users\Desktop\\Intermediate\ProjectFiles.generated.cpp.obj 1

If I completly comment out BTService_SenseCheck.h and BTService_SenseCheck.cpp I dont get this error anymore, however if I just comment out the custom code I get this error (an empty version of the class).

This is the code I am using, some lines have already been tried to be comment out.
.cpp

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

#include ".h"
#include "BehaviorTree/BehaviorTree.h"
#include "BehaviorTree/BehaviorTreeComponent.h"
#include "BehaviorTree/BlackboardComponent.h"
#include "BehaviorTree/Blackboard/BlackboardKeyAllTypes.h"
#include "Enemy_AI_Controller.h"
#include "HellskriegCppCharacter.h"
#include "UseFullFunctions.h"
#include "AISound.h"
#include "BTService_MemoryMarker.h"
#include "Kismet/KismetSystemLibrary.h"
#include "BTService_SenseCheck.h"

UBTService_SenseCheck::UBTService_SenseCheck()
{
	bCreateNodeInstance = true;
	SeesPlayer = false;
	HearsPlayer = false;
}


void UBTService_SenseCheck::TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds)
{
	AEnemy_AI_Controller* EnemyController = Cast<AEnemy_AI_Controller>(OwnerComp.GetAIOwner());
	//Make sure the cast succeeds
	if (EnemyController)
	{
		//Get all players
		TSubclassOf<AHellskriegCppCharacter> ClassToFind;
		TArray<AActor*> Players;
		UGameplayStatics::GetAllActorsOfClass(GetWorld(), ClassToFind, Players);

		//Vision
		for (int i = 0; i < Players.Num(); i++)
		{
			if (UseFullFunctions::AngleBetweenPoints(Players[i]->GetActorLocation() - EnemyController->GetPawn()->GetActorLocation(), EnemyController->GetPawn()->GetActorForwardVector()))
			{
				ACharacter* Character = Cast<ACharacter>(EnemyController->GetPawn());
				if (Character)
				{
					TArray<AActor*> ActorsToIgnore;
					ActorsToIgnore.Add(Character->GetCapsuleComponent()->GetOwner());
					FHitResult OutHit;
					UKismetSystemLibrary::LineTraceSingle_NEW(GetWorld(), EnemyController->GetPawn()->GetActorLocation(), Character->GetActorLocation(), ETraceTypeQuery(ECC_Camera), false, ActorsToIgnore, EDrawDebugTrace::None, OutHit, true);
					//Did the enemy see a friendly (other team)
					ABasicFriendly* HitCharacter = Cast<ABasicFriendly>(OutHit.GetActor());
					if (HitCharacter)
					{
						SeesPlayer = true;
						OwnerComp.GetBlackboardComponent()->SetValueAsObject(FName("Target"), HitCharacter);
					}
				}
			}
		}
		//END vision

		//Hearing
		TArray<AActor*> AISounds;
		UGameplayStatics::GetAllActorsOfClass(GetWorld(), ClassToFind, AISounds);
		float BestSoundDistance = 99999.f;
		for (int i = 0; i < AISounds.Num(); i++)
		{
			AAISound* CurrentSound = Cast<AAISound>(AISounds[i]);
			if(CurrentSound->Causer != EnemyController->GetOwner())
			{
				float Distance = (EnemyController->GetPawn()->GetActorLocation() - CurrentSound->GetActorLocation()).Size();
				if (CurrentSound->Obvious)
				{
					Distance /= 2;
				}
				Distance /= CurrentSound->Strength;
				if (Distance < BestSoundDistance)
				{
					BestSoundDistance = Distance;
					if (Distance <= EnemyController->HearingRange)
					{
						AAI_MemoryMarker* MemoryMarker = GetWorld()->SpawnActor<AAI_MemoryMarker>(MemoryMarkerToSpawn->StaticClass(), CurrentSound->GetActorLocation(), FRotator(0.0f, 0.0f, 0.0f));
						OwnerComp.GetBlackboardComponent()->SetValueAsObject(FName("MemoryMarker"), MemoryMarker);
					}
				}
			}
		}
		//END Hearing

		//Use gathered info
		if (SeesPlayer || HearsPlayer)
		{
			OwnerComp.GetBlackboardComponent()->SetValueAsEnum(FName("State"), 2);
		}
		//TODO: Get highest thread and set it to target
	}
}

.h

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

#pragma once

#include "BehaviorTree/BTService.h"
#include "BTService_SenseCheck.generated.h"



UCLASS()
class HELLSKRIEGCPP_API UBTService_SenseCheck : public UBTService
{
	GENERATED_BODY()


public:
	//Constructor
	UBTService_SenseCheck();

	//Tick
	virtual void TickNode(UBehaviorTreeComponent& OwnerComp, uint8* NodeMemory, float DeltaSeconds) override;
	
private:
	bool SeesPlayer;
	bool HearsPlayer;

protected:
	UPROPERTY(VisibleAnywhere, BlueprintReadWrite)
		AActor* MemoryMarkerToSpawn;
};

The problem seems to be within the egine, however I am not sure.

1 Like

Hey ,

Can you show me how you are using the BTService in your code?

Thanks.

I have edited my original post, I am trying to use this via a behavior tre, however I haven’t place this in the behaviour treesince it won’t compile

In your .Build.cs file, have you added “AIModule” to the “PublicDependencyModuleNames.AddRange”? Like:

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

Yes I have

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

I also now can confirm that the name of the class is not the problem since I have tried to add another BTService class which gives the same error

I will have a look in the shooter example from Epic since I know it has some c++ in the behavior tree. I hope that I can find the problem…

It has no c+ BTServices…

Hey ,

Sorry for the delay.

Can you update your Game.Build.cs file to this:

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

Then, recompile the project. This fixed the issue on my end.

2 Likes

after chaninging it to this:

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

It worked

Thank you very much!

Hey ,

Glad that helped.

Thank you for submitting a bug report, however at this time we believe that the issue you are describing is not actually a bug with the Unreal Engine, and so we are not able to take any further action on this. If you still believe this may be a bug, please provide steps for us to reproduce the issue, and we will continue our investigation.