Game Instance - Unresolved External Symbol

Hi guys

I’m pretty new to C++, and following through a tutorial book which has got me creating a new Game Instance class (RPGGameInstance), but I’m having an error each time I try to compile.

Here’s what I’ve got in the header file:

#pragma once

#include "Engine/GameInstance.h"
#include "RPGGameInstance.generated.h"

UCLASS()
class RPG_API URPGGameInstance : public UGameInstance
{
	GENERATED_BODY()

		URPGGameInstance(const class FObjectInitializer& ObjectInitializer);
};

I can’t see anything wrong with it, and I’ve used ObjectInitializer in the exact same way for another class, and it works perfectly.

When I hover above the “UCLASS()” declaration, Intellisense says “this declaration has no storage class or type specifier”, and when I hover above the “class” declaration below it, it says “expected a ;”.

When I look at the UE4 Message Log, I get this:

Error RPGGameInstance.cpp.obj : error LNK2019: unresolved external symbol "private: __cdecl URPGGameInstance::URPGGameInstance(class FObjectInitializer const &)" (??0URPGGameInstance@@AEAA@AEBVFObjectInitializer@@@Z) referenced in function "public: static void __cdecl URPGGameInstance::__DefaultConstructor(class FObjectInitializer const &)" (?__DefaultConstructor@URPGGameInstance@@SAXAEBVFObjectInitializer@@@Z)

Does anybody have any idea what’s going wrong here?

Any information will be appreciated!

Cheers

Well, typically after asking for help, I found out the issue. I just needed to put this into the .cpp for that class:

URPGGameInstance::URPGGameInstance(const class FObjectInitializer& objectInitializer) : Super(objectInitializer)
{

}
1 Like

Just a quick note. When using GENERATED_BODY() macro you dont need need to use the FObjectInitializer. You can declare the method like this:

URPGGameInstance();

Thanks, ryanjon2040 - Good to know :slight_smile: