RerunConstructionScripts called on actor that has begun play leading to failure to spawn actor in component's BeginPlay

Hello,

I have a component that spawns an actor in its BeginPlay method and an actor BP that makes use of that component. This works without trouble when I play a level with the actor BP instance in it. When I open that level from another level via the Open Level BP node I get the following error message:

LogSpawn: Warning: SpawnActor failed because we are running a ConstructionScript (Actor)

The call to SpawnActor returns null. This is the callstack leading to it:

UnrealEditor-UXTools.dll!UUxtBoundsControlComponent::BeginPlay() Line 508 C++
UnrealEditor-Engine.dll!UActorComponent::RegisterComponentWithWorld(UWorld * InWorld=0x00000625c38dc800, FRegisterComponentContext * Context=0x0000000000000000) Line 1309 C++
UnrealEditor-Engine.dll!USimpleConstructionScript::RegisterInstancedComponent(UActorComponent * InstancedComponent=0x00000625b98f4d80) Line 634 C++
UnrealEditor-Engine.dll!AActor::ExecuteConstruction(const UE::Math::TTransform & Transform={…}, const FRotationConversionCache * TransformRotationCache=0x0000000e1657b840, const FComponentInstanceDataCache * InstanceDataCache=0x00000625b9873b98, bool bIsDefaultTransform=false) Line 792 C++
> UnrealEditor-Engine.dll!AActor::RerunConstructionScripts() Line 535 C++
UnrealEditor-Engine.dll!FActorDeferredScriptManager::ProcessAsyncTasks(bool bLimitExecutionTime) Line 83 C++
UnrealEditor-Engine.dll!FAssetCompilingManager::ProcessAsyncTasks(bool bLimitExecutionTime) Line 349 C++
UnrealEditor.exe!FEngineLoop::Tick() Line 5257 C++

Is it not allowed to spawn actors from a component’s BeginPlay? Otherwise, is this a UE bug? I’m using UE 5.0.2. Any help would be much appreciated. Thanks!

Cheers,

Luis

You can pass FActorSpawnParameters to SpawnActor and set bAllowDuringConstructionScript to true on it.

Thank you @UnrealEverything . That would allow me to bypass the check which in general I don’t want to do, as it may catch genuine bad uses. The underlying issue is that RerunConstructionScripts() is being called on an actor that has already begun play. It seems to be a known issue, this is what Epic told me via UDN:

I think you might be running into this bug Unreal Engine Issues and Bug Tracker (UE-157303). The fix is targeted for 5.1, but it looks like we have a tentative fix for this in CL#18781200 if you want to try it out.