Object Not Packaged Fatal Error when using NewObject<>

Hello,

I am trying to instantiate a new actor component (inherited from UActorComponent) in C++ using the NewObject<> function.

The code looks something like:

	CurrentRoundTimer = NewObject<UMyTimer>(this, "NewTimer");
	this->AddInstanceComponent(CurrentRoundTimer);
	CurrentRoundTimer->RegisterComponent();

I am doing this in the BeginPlay function of the Actor class that I’m calling this in.

Unreal keeps crashing with the error:

Fatal error: [File:D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp] [Line: 3054] Object is not packaged: MyTimer NewTimer

I dont really understand what I could be doing wrong. It looks to me like I’m using the NewObject<> function correctly. The crash report does point to this line in the call stack.

Additionally, I am see these lines in the logs which say “could not find existing class ‘ClassName’ in package /Script/‘ProjectName’ for reload, assuming new or modified class” for almost all of my classes except a few.

I’ve been trying to fix this for a while and I’m still scratching my head. Any help would be appreciated.
Thank You :slight_smile:

Turns out that I had forgotten to add the calling Actor in the scene.

Its a bit strange that the code execution reached the line in the file even though an object had not yet been instantiated (perhaps this is because of the class default object?)