FObjectInitializer::Get() crash error

Hi

I’m trying to edit a plugin for LiveLink. I’m trying to get the Timecode from Unreal but i’m getting a crash with the error:

FObjectInitializer::Get() can only be used inside of UObject-derived class constructor.

As the error says, my plugin class isn’t derived from UObject. Is there a way to still get this information?

This is my code:

FQualifiedFrameTime sceneTime;
UTimecodeProvider GiverOfTimecode;

sceneTime = GiverOfTimecode.GetQualifiedFrameTime();

UObjects cannot live on the stack, you need to allocate one using NewObject. Otherwise when the default constructor runs FObjectInitializer::Get() is called in the background. But since NewObject wasn’t called there is no current FObjectInitializer (for the UObject being constructed). Also note that UTimecodeProvider is marked abstract so should not be instantiated anyway. NewObject checks for that.

There are several ways you could solve this:

  • use UEngine::GetTimecodeProvider
  • add a property or function parameter so you can set/pass the TimecodeProvider to use
  • you could use one of the non-abstract implementations of UTimecodeProvider for example USystemTimeTimecodeProvider
  • the MediaFrameworkUtilities plugin has a UMediaProfile which holds a TimecodeProvider if you have access to such a profile
  • take a look at UAppleARKitSettings::GetTimecodeProvider() which has support for settings and falls back onto the default UAppleARKitTimecodeProvider
1 Like