From eb7d5e5df3b72435a9d152d0c36f799a57ff43c8 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 7 Dec 2023 11:50:24 +0100 Subject: [PATCH] Fix crash when spawning actor from asyc thread into the SceneObject #2033 --- Source/Engine/Level/Actor.cpp | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index addb4861e..bc568458e 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -239,14 +239,8 @@ const Guid& Actor::GetSceneObjectId() const void Actor::SetParent(Actor* value, bool worldPositionsStays, bool canBreakPrefabLink) { - // Check if value won't change if (_parent == value) return; - if (IsDuringPlay() && !IsInMainThread()) - { - LOG(Error, "Editing scene hierarchy is only allowed on a main thread."); - return; - } #if USE_EDITOR || !BUILD_RELEASE if (Is()) { @@ -265,6 +259,13 @@ void Actor::SetParent(Actor* value, bool worldPositionsStays, bool canBreakPrefa // Detect it actor is not in a game but new parent is already in a game (we should spawn it) const bool isBeingSpawned = !IsDuringPlay() && newScene && value->IsDuringPlay(); + // Actors system doesn't support editing scene hierarchy from multiple threads + if (!IsInMainThread() && (IsDuringPlay() || isBeingSpawned)) + { + LOG(Error, "Editing scene hierarchy is only allowed on a main thread."); + return; + } + // Handle changing scene (unregister from it) const bool isSceneChanging = prevScene != newScene; if (prevScene && isSceneChanging && wasActiveInTree)