Crash on HotReload "Tried to get the current ObjectInitializer, but none is set"

getting a strange crash when compiling.

  1. I haven’t touched any code involving NewObject or ObjectInitializer at all today, yet I’ve only seen this problem today. Possibly an issue with 5.3.1?
  2. Without changing any code in between, it compiles just fine after the editor reopens.
Fatal error: [File:D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectThreadContext.cpp] [Line: 32] Tried to get the current ObjectInitializer, but none is set. Please use NewObject to construct new UObject-derived classes.

UnrealEditor_CoreUObject!FObjectInitializer::Get() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectGlobals.cpp:4423]
UnrealEditor_Engine!UTexture::UTexture() [D:\build\++UE5\Sync\Engine\Source\Runtime\Engine\Private\Texture.cpp:230]
UnrealEditor_Engine!UTextureRenderTarget2D::UTextureRenderTarget2D() [D:\build\++UE5\Sync\Engine\Intermediate\Build\Win64\UnrealEditor\Inc\Engine\UHT\TextureRenderTarget2D.gen.cpp:400]
UnrealEditor_Engine!UCanvasRenderTarget2D::UCanvasRenderTarget2D() [D:\build\++UE5\Sync\Engine\Intermediate\Build\Win64\UnrealEditor\Inc\Engine\UHT\CanvasRenderTarget2D.gen.cpp:410]
UnrealEditor_Experiments_patch_1!USpriteSheetCRT::__VTableCtorCaller() [D:\My Documents\Unreal Projects\Experiments\Source\Experiments\Portraits\SpriteSheetCRT.h:15]
UnrealEditor_CoreUObject!UClass::HotReloadPrivateStaticClass() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Class.cpp:5931]
UnrealEditor_CoreUObject!GetPrivateStaticClassBody() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\Class.cpp:6529]
UnrealEditor_Experiments_patch_1!USpriteSheetCRT::GetPrivateStaticClass() [D:\My Documents\Unreal Projects\Experiments\Intermediate\Build\Win64\UnrealEditor\Inc\Experiments\UHT\SpriteSheetCRT.gen.cpp:110]
UnrealEditor_CoreUObject!UClassRegisterAllCompiledInClasses() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectBase.cpp:697]
UnrealEditor_CoreUObject!ProcessNewlyLoadedUObjects() [D:\build\++UE5\Sync\Engine\Source\Runtime\CoreUObject\Private\UObject\UObjectBase.cpp:896]
UnrealEditor_LiveCoding!FLiveCodingModule::AttemptSyncLivePatching() [D:\build\++UE5\Sync\Engine\Source\Developer\Windows\LiveCoding\Private\LiveCodingModule.cpp:814]
UnrealEditor_LiveCoding!FLiveCodingModule::Tick() [D:\build\++UE5\Sync\Engine\Source\Developer\Windows\LiveCoding\Private\LiveCodingModule.cpp:767]
UnrealEditor_LiveCoding!TBaseRawMethodDelegateInstance<0,FLiveCodingModule,void __cdecl(void),FDefaultDelegateUserPolicy>::ExecuteIfSafe() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Delegates\DelegateInstancesImpl.h:534]
UnrealEditor!TMulticastDelegate<void __cdecl(void),FDefaultDelegateUserPolicy>::Broadcast() [D:\build\++UE5\Sync\Engine\Source\Runtime\Core\Public\Delegates\DelegateSignatureImpl.inl:956]
UnrealEditor!FEngineLoop::Tick() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\LaunchEngineLoop.cpp:6093]
UnrealEditor!GuardedMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Launch.cpp:188]
UnrealEditor!GuardedMainWrapper() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:118]
UnrealEditor!LaunchWindowsStartup() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:258]
UnrealEditor!WinMain() [D:\build\++UE5\Sync\Engine\Source\Runtime\Launch\Private\Windows\LaunchWindows.cpp:298]
UnrealEditor!__scrt_common_main_seh() [D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288]
kernel32
ntdll

code for USpriteSheetCRT (public UCanvasRenderTarget2D), in the event it matters:

uint32 USpriteSheetCRT::CalcTextureMemorySizeEnum(ETextureMipCount Enum) const
{
	//copied from UTextureRenderTarget2D, as Super or simply not overriding don't work

	// Calculate size based on format.  All mips are resident on render targets so we always return the same value.
	EPixelFormat Format = GetFormat();
	int32 BlockSizeX = GPixelFormats[Format].BlockSizeX;
	int32 BlockSizeY = GPixelFormats[Format].BlockSizeY;
	int32 BlockBytes = GPixelFormats[Format].BlockBytes;
	int32 NumBlocksX = (SizeX + BlockSizeX - 1) / BlockSizeX;
	int32 NumBlocksY = (SizeY + BlockSizeY - 1) / BlockSizeY;
	int32 NumBytes = NumBlocksX * NumBlocksY * BlockBytes;
	return NumBytes;
}

void USpriteSheetCRT::OnReceiveUpdate(class UCanvas* Canvas, int32 Width, int32 Height)
{
	UE_LOG(LogTemp, Log, TEXT("OnReceiveUpdate"));

	UMaterialInstanceDynamic* bodyDMI = UKismetMaterialLibrary::CreateDynamicMaterialInstance(this, BodyMaterial);
	bodyDMI->SetTextureParameterValue("Upper", UpperBody);
	bodyDMI->SetTextureParameterValue("Lower", LowerBody);
	FLinearColor skinHSL = UColorQuartetBFL::RandomSkinHSL();
	bodyDMI->SetVectorParameterValue("Skin", UColorQuartetBFL::HSLtoRGB(skinHSL));
	Canvas->K2_DrawMaterial(bodyDMI, FVector2D(0,0), FVector2D(Width, Height), FVector2D(0,0));

	int coords[6][2] = { {118, 109}, {133, 382}, {136, 710}, {136, 1010}, {120, 1270}, {140.5, 1663.5} };

	FVector2D scale = FVector2D(6,6);
	UMaterialInstanceDynamic* headDMIIdle = UKismetMaterialLibrary::CreateDynamicMaterialInstance(this, HeadMaterial);
	headDMIIdle->SetTextureParameterValue("Eyes", Eyes);
	headDMIIdle->SetTextureParameterValue("Mouth", Mouth);
	headDMIIdle->SetTextureParameterValue("Hair", Hair);
	Canvas->K2_DrawMaterial(headDMIIdle, FVector2D(coords[0][0] - 125, coords[0][1] - 150), FVector2D(Width, Height), FVector2D::Zero(), scale);
	Canvas->K2_DrawMaterial(headDMIIdle, FVector2D(coords[1][0] - 125, coords[1][1] - 150), FVector2D(Width, Height), FVector2D::Zero(), scale);
	Canvas->K2_DrawMaterial(headDMIIdle, FVector2D(coords[5][0] - 125, coords[5][1] - 150), FVector2D(Width, Height), FVector2D::Zero(), scale, 15, FVector2D(125/1500.0f, 150/1800.0f));

	UMaterialInstanceDynamic* headDMIAttack = UKismetMaterialLibrary::CreateDynamicMaterialInstance(this, HeadMaterial);
	headDMIAttack->SetTextureParameterValue("Eyes", Eyes);
	headDMIAttack->SetScalarParameterValue("EyeIndex", 1);
	headDMIAttack->SetTextureParameterValue("Mouth", Mouth);
	headDMIAttack->SetScalarParameterValue("MouthIndex", 2);
	headDMIAttack->SetTextureParameterValue("Hair", Hair);
	Canvas->K2_DrawMaterial(headDMIAttack, FVector2D(coords[2][0] - 125, coords[2][1] - 150), FVector2D(Width, Height), FVector2D::Zero(), scale);
	Canvas->K2_DrawMaterial(headDMIAttack, FVector2D(coords[3][0] - 125, coords[3][1] - 150), FVector2D(Width, Height), FVector2D::Zero(), scale);

	UMaterialInstanceDynamic* headDMIBack = UKismetMaterialLibrary::CreateDynamicMaterialInstance(this, HeadMaterial);
	headDMIBack->SetTextureParameterValue("Eyes", Eyes);
	headDMIBack->SetTextureParameterValue("Mouth", Mouth);
	headDMIBack->SetTextureParameterValue("Hair", Hair);
	headDMIBack->SetScalarParameterValue("Facing", 2);
	Canvas->K2_DrawMaterial(headDMIBack, FVector2D(642.5 - 125, 1639.5 - 150), FVector2D(Width, Height), FVector2D::Zero(), scale, 15, FVector2D(125 / 1500.0f, 150 / 1800.0f));
}

//couldn't find a better place to put this one thing, so it gets to be a function for right now
//this is all just experimental for right now
void USpriteSheetCRT::Setup()
{
	OnCanvasRenderTargetUpdate.AddDynamic(this, &USpriteSheetCRT::OnReceiveUpdate);


}

(nothing special in SpriteSheetCRT.h, just declarations of variables and the above functions.)

1 Like

I’m having the same error. It seems that it traces back to

UTexture::UTexture(FVTableHelper& Helper)
	: TextureReference(*new FTextureReference())
{
}

Somewhere in the above code it is trying to get an FObjectInitializer. This struct is used to fill UProperties after the c++ constructor is called. I think it’s supposed to copy properties from the default class instance, but it can’t find it or there’s a problem with it is my best guess.

So the solution that works for now is to create a copy of your render target class under a different name and use that one instead. I’m not sure why.

can you elaborate? I’m not sure what you mean by “create a copy of your render target class under a different name”. Do you mean copy-paste the code from TextureRenderTarget2D / CanvasRenderTarget2D / whatever to avoid deriving from those classes? If so, how far up the inheritance chain?

Currently the solution I’ve had to rely on is making SpriteSheetCRT in Blueprint instead. While it works (so far), I’d like to be able to do this in C++; I find C++ easier to read, write, and comment than BP.

also, just tested in 5.2.1 and it still happened (same error message, but don’t have symbols downloaded for 5.2, so no trace), so contrary to my guess in the OP, it’s not new to 5.3. Did require referencing the class in a BP before the compile triggered a crash.

Issue seems that UTexture is implementing the HotReloading constructor using the FVTableHelper incorrectly. It should pass along the Helper struct to it’s parent class, signifying its being hot-reloaded. Omitting that will call the default constructor, which expects the FObjectInitializer.

The fix is an engine fix:

Old Code:

UTexture::UTexture(FVTableHelper& Helper)
	: TextureReference(*new FTextureReference())
{
}

fix:

UTexture::UTexture(FVTableHelper& Helper)
	: Super(Helper)
	, TextureReference(*new FTextureReference())
{
}

This will probably always trigger if a module with a subclass of UTexture is being hot-reloaded.

I’m having the same issue inheriting the class UCanvasRenderTarget2D

are there instructions on how to do an engine fix? I tried Building Unreal Engine from Source | Unreal Engine 5.3 Documentation, but ran out of storage space trying to compile. So either I did it wrong, or 200GB isn’t enough and I’ll have to hope that Epic does it themselves next time there’s an update.

You easily need 300GB-600GB or more of Storage depending on the number of Platform you compile for.