This is the method that I have created:
template <typename T>
void UEventSystemManager::SubscribeToEvent(const FName EventName, T *testGame, void (T::*func) ())
{
FTestEventDelegate* EventDelegate = EventDelegates.Find(EventName);
EventDelegate->AddUniqueDynamic(testGame, func);
}
I am trying to call it in a different class constructor like below:
ATestGameElement::ATestGameElement()
{
UEventSystemManager* EventManager = UEventSystemManager::GetInstance();
EventManager->SubscribeToEvent("TestFiringEvent",this, &ATestGameElement::HandleEvent);
}
This is my HandleEvent:
void ATestGameElement::HandleEvent()
{
// Handle the event here
UE_LOG(LogTemp, Warning, TEXT("Event handled by UTestGameElement"));
GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Green, TEXT("Success"));
}
This is throwing me error LNK2019 unresolved external symbol error. I am unable to resolve it its been 2 days. I need help
Full code:
TestGameElement.cpp
#include "TestGameElement.h"
#include "EventSystemManager.h"
#include <functional>
#include "EventDispatcher.h"
void ATestGameElement::HandleEvent()
{
// Handle the event here
UE_LOG(LogTemp, Warning, TEXT("Event handled by UTestGameElement"));
GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Green, TEXT("Success"));
}
void ATestGameElement::TestEvent()
{
// Handle the event here
UE_LOG(LogTemp, Warning, TEXT("Event handled by UTestGameElement"));
GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Green, TEXT("Success"));
}
ATestGameElement::ATestGameElement()
{
UEventSystemManager* EventManager = UEventSystemManager::GetInstance();
GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Green, TEXT("Test Game Element Initialized"));
EventManager->RegisterEvent("Teeeeeest");
auto callback = [this](){
HandleEvent();
};
//void (ATestGameElement::*func) = TestEvent();
EventManager->SubscribeToEvent("TestFiringEvent",this, &ATestGameElement::HandleEvent);
}
EventSystemManager.cpp
#include "EventSystemManager.h"
UEventSystemManager* UEventSystemManager::Instance = nullptr;
UEventSystemManager::UEventSystemManager()
{
if (Instance == nullptr)
{
Instance = this;
}
}
UEventSystemManager* UEventSystemManager::GetInstance()
{
return Instance;
}
void UEventSystemManager::RegisterEvent(const FName EventName)
{
GEngine->AddOnScreenDebugMessage(-1, 10.0, FColor::Green, TEXT("Registered event"));
EventDelegates.Add(EventName, FTestEventDelegate());
}
//void (T::*func)
template <typename T>
void UEventSystemManager::SubscribeToEvent(const FName EventName, T *testGame, void (T::*func) ())
{
FTestEventDelegate* EventDelegate = EventDelegates.Find(EventName);
EventDelegate->AddUniqueDynamic(testGame, func);
}
This is the exact error message:
TestGameElement.cpp.obj : error LNK2019: unresolved external symbol “public: void __cdecl UEventSystemManager::SubscribeToEvent(class FName,class ATestGameElement ,void (__cdecl ATestGameElement::)(void))”
: fatal error LNK1120: 1 unresolved externals