UObject outer is template during PIE

Hi,

back to objects again… So i have pretty simple UObject based class(UMyObject) which stores pointer to character(ACharacter for example).

UMyObject is being initialized inside character constructor, object pointer is set inside its constructor via GetOuter().

So what i have here: spawned character has UMyObject, but it’s pointer set to template object, as it crashes engine if i attempt to attach actor to another using the pointer printing corresponding message to the log. It works fine if i set pointer inside ACharacter::BeginPlay. Pseudo code for better understanding:

UMyObject()
{
    Owner = Cast<ACharacter>(GetOuter());
}

ACharacter()
{
    MyObject = NewObject(this);
}

What actually confuses me here is that this happens only for some of the objects…

I initialize few other objects the same way before initializing UMyObject, and it does not happen for them.

Glad to see any help :slight_smile:

LogAlone: Constructor owner - BP_Player_C /Game/Maps/UEDPIE_0_Default.Default:PersistentLevel.BP_Player_C_0
LogAlone: PreBeginPlay owner - AlonePlayerCharacter /Script/Alone.Default__AlonePlayerCharacter
LogAlone: PostBeginPlay owner - BP_Player_C /Game/Maps/UEDPIE_0_Default.Default:PersistentLevel.BP_Player_C_0

Owner set in constructor seems to be ok, but owner is then set to CDO in BeginPlay() right after calling Super::BeginPlay() and before setting owner manually once again.

So i decided to try initializing object in PostInitializeComponents. Owner is not getting reset to CDO in BeginPlay now, but it looks like a “design-hack” to initialize essential objects in place other than constructor.