FObjectFinderOptional constructor check issue

I’ve recently picked up FObjectFinder to dynamically load materials in the game code. I’ve created a TextRenderer initializer class, that setups basic TextRenderer info and attaches it to specified component, rendering debug info in game.
Consider the following code:


//Small utility class that encapsulates initializing TextRenderer attached to specified component.
class DebugTextRenderer
    UMaterial* TextMaterial;


	static ConstructorHelpers::FObjectFinderOptional<UMaterial> materialObjectFinder(TEXT("path_to_the_material"));
	TextMaterial = materialObjectFinder.Get();

These code pieces worked fine for me in a long term. However, recently, upon trying to add new C++ class in UE editor it crashed during code recompilation. What’s really weird is that it crashed in the Get method of object finder, in the “CheckIfInConstructor” check:

T* Get()
	if (!Object && ObjectToFind)
		FString PathName(ObjectToFind);

		Object = ConstructorHelpersInternal::FindOrLoadObject<T>(PathName);
		ValidateObject( Object, PathName, ObjectToFind );

		ObjectToFind = nullptr; // don't try to look again
	return Object;

Upon investigating the callstack, the method Get() is called from the DebugTextRenderer constructor. What’s really weird is that:

  1. It crashes because the method thinks it’s called outside of a constructor, but it isn’t.

  2. It doesn’t crash in any other scenario (the TextRenderer component I initialize with this class works fine until the .dll’s are recompiled by UE).

Any suggestions on what I’m missing? I’ve tried to make the TextMaterial variable static to ensure it only gets initialized once, but this code is being called from a thread different than the original component constructors.

After some time spent debugging I’ve found the solution. Instead of writing “raw” c++ class that encapsulated UTextRenderComponent I’ve inherited it in my DebugTextRenderer wrapper.

The issue was probably due to the DebugTextRenderer not being an UCLASS(), which gave it weird construction behaviour.