[Fatal Error] When trying to load and set a ChildActorClass to UChildActorComponent in build.

Hello there,

I had a problem recently when trying to load and assign a class to a UChildActorComponent from the C++ constructor.
It works perfectly fine in editor but whenever I try to run the packaged executable, I get an error before it can even launch the game (on Oculus Quest).

Error logs look like this (I just replaced classes name by the name written in the following example):
Fatal error: [File: D:/Build/++UE4/Sync/Engine/Source/Runtime/CoreUObject/Private/Serialization/AsyncLoading.cpp] [Line: 3393]
02-19 12:01:49.401 17437 17455 D UE4 : SomeClass_BP /Game/SomePath/ASomeActor_BP.Default__ASomeActor_BP_C:MyChildActorComponent.MyChildActorComponent_SomeClass_BP_CAT was found in memory and is an export but does not have all load flags.

I more or less have something like this:



ASomeActor::ASomeActor(const FObjectInitializer& ObjectInitializer): Super(ObjectInitializer)
{
    SomeChildActorComponent = CreateDefaultSubobject<UChildActorComponent>("MyChildActorComponent");
    // Load BP class from the assets
    static ConstructorHelpers::FClassFinder<AActor> SomeClass_BP(TEXT("/Game/Path/To/My/Blueprint/SomeClass_BP"));
    
SomeChildActorComponent->SetChildActorClass(SomeClass_BP.Class);

    // I tried with LoadClass syntax too
    UClass* SomeClass_BP = LoadClass<AActor>(nullptr, TEXT("Blueprint'/Game/Path/To/My/Blueprint/SomeClass_BP.SomeClass_BP_C'"));
    SomeChildActorComponent->SetChildActorClass(SomeClass_BP);

    // I tried with a static class too
    SomeChildActorComponent->SetChildActorClass(SomeClass::StaticClass());
}
 


The error talks about load flags so I checked the ELoadFlag documentation and tried to provide some flags to the LoadClass method (I tried LOAD_Async) without any success.
I also checked ue4 source code around AsyncLoading.cpp [Line: 3393], but couldn’t get any clue about why this is happening.

Any idea or something I’m doing wrong?

Thank you!

u can send SetChildActorClass code to beginplay()

void
ASomeActor::BeginPlay()
{
Super::BeginPlay();

SomeChildActorComponent->SetChildActorClass(SomeClass::StaticClass());
}