Description

Actors that are deferred spawned on BeginPlay can be added to the world while AWorldSettings::NotifyBeginPlay is still iterating the world's actors and dispatching BeginPlay. AActor::DispatchBeginPlay doesn't check bHasFinishedSpawning before calling BeginPlay on the partially constructed actor.

Steps to Reproduce
  • Deferred spawn an actor in another actor's BeginPlay (GetWorld()->SpawnActorDeferred<AMyActor>(AMyActor::StaticClass(), FTransform(), this, nullptr, ESpawnActorCollisionHandlingMethod::AlwaysSpawn)[Image Removed]
  • Set a timer for the next tick to finish spawning the actor
  • Note that BeginPlay is called on the partially spawned actor before FinishSpawning is called
Callstack

> UnrealEditor-MyProject3.dll!AMyActor::BeginPlay() Line 17 C++
UnrealEditor-Engine.dll!AActor::DispatchBeginPlay(bool bFromLevelStreaming) Line 4161 C++
UnrealEditor-Engine.dll!AWorldSettings::NotifyBeginPlay() Line 305 C++
UnrealEditor-Engine.dll!AGameStateBase::HandleBeginPlay() Line 226 C++
UnrealEditor-Engine.dll!UWorld::BeginPlay() Line 5228 C++
UnrealEditor-Engine.dll!UGameInstance::StartPlayInEditorGameInstance(ULocalPlayer * LocalPlayer, const FGameInstancePIEParameters & Params) Line 551 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::CreateInnerProcessPIEGameInstance(FRequestPlaySessionParams & InParams, const FGameInstancePIEParameters & InPIEParameters, int InPIEInstanceIndex) Line 3233 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::OnLoginPIEComplete_Deferred(int LocalUserNum, bool bWasSuccessful, FString ErrorString, FPieLoginStruct DataStruct) Line 1680 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::CreateNewPlayInEditorInstance(FRequestPlaySessionParams & InRequestParams, const bool bInDedicatedInstance, const EPlayNetMode InNetMode) Line 1943 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::StartPlayInEditorSession(FRequestPlaySessionParams & InRequestParams) Line 2964 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::StartQueuedPlaySessionRequestImpl() Line 1257 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::StartQueuedPlaySessionRequest() Line 1160 C++
UnrealEditor-UnrealEd.dll!UEditorEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 1811 C++
UnrealEditor-UnrealEd.dll!UUnrealEdEngine::Tick(float DeltaSeconds, bool bIdleMode) Line 531 C++
UnrealEditor.exe!FEngineLoop::Tick() Line 5801 C++
[Inline Frame] UnrealEditor.exe!EngineTick() Line 61 C++
UnrealEditor.exe!GuardedMain(const wchar_t * CmdLine) Line 188 C++
UnrealEditor.exe!LaunchWindowsStartup(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * __formal, int nCmdShow, const wchar_t * CmdLine) Line 231 C++
UnrealEditor.exe!WinMain(HINSTANCE__ * hInInstance, HINSTANCE__ * hPrevInstance, char * pCmdLine, int nCmdShow) Line 282 C++

Have Comments or More Details?

There's no existing public thread on this issue, so head over to Questions & Answers just mention UE-186291 in the post.

0
Login to Vote

Backlogged
ComponentUE - Gameplay
Affects Versions5.2
Target Fix5.4
CreatedMay 18, 2023
UpdatedMay 22, 2023