I want use singleton pattern.
But i saw error log (unresolved external symbol “private: static class ABuildingManager * ABuildingManager::TempInstance” (?TempInstance@ABuildingManager@@0PEAV1@EA)).
I don’t know the reason for the error. help me please.
BuildingManager.h
UCLASS()
class ABANDONEDCAMP_API ABuildingManager : public AActor
{
GENERATED_BODY()
public:
ABuildingManager();
private:
static ABuildingManager* TempInstance;
public:
static ABuildingManager* Instance();
protected:
virtual void BeginPlay() override;
...
}
BuildingManager.cpp
#include "BuildingManager.h"
#include "Kismet/GameplayStatics.h"
ABuildingManager::ABuildingManager()
{
PrimaryActorTick.bCanEverTick = true;
}
ABuildingManager* ABuildingManager::Instance()
{
ABuildingManager* BM;
if (TempInstance) {
BM = TempInstance;
}
else {
UWorld* world = GEngine->GameViewport->GetWorld();
BM = Cast<ABuildingManager>(UGameplayStatics::GetActorOfClass(world, ABuildingManager::StaticClass()));
if (!BM) {
BM = world->SpawnActor<ABuildingManager>();
}
}
return BM;
}