BTW, you can make a nice, clean “AddComponent()” function by detecting the thread context and using the appropriate way to instantiate. Kinda annoying that we have to do this … but not aware there is another way?
Code for detecting thread context. There’s a function for both because sometime it reads better either way.
bool UObjectUtilities::GetThreadContextIsContructor()
{
FUObjectThreadContext& ThreadContext = FUObjectThreadContext::Get();
if (ThreadContext.IsInConstructor > 0)
{
return true;
}
else
{
return false;
}
}
bool UObjectUtilities::GetThreadContextIsRuntime()
{
FUObjectThreadContext& ThreadContext = FUObjectThreadContext::Get();
if (ThreadContext.IsInConstructor > 0)
{
return false;
}
else
{
return true;
}
}