From dbec1389e8ae6e62c7ab0859cb53c3731db8f2b7 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 1 Mar 2021 10:42:45 +0100 Subject: [PATCH] Fix using Scripts in async --- Source/Engine/Scripting/Script.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/Source/Engine/Scripting/Script.cpp b/Source/Engine/Scripting/Script.cpp index e1f15e44e..e1d2da73a 100644 --- a/Source/Engine/Scripting/Script.cpp +++ b/Source/Engine/Scripting/Script.cpp @@ -77,14 +77,12 @@ void Script::SetParent(Actor* value, bool canBreakPrefabLink) // Check if value won't change if (_parent == value) return; - if (!IsInMainThread()) + if (IsDuringPlay() && !IsInMainThread()) { LOG(Error, "Editing scene hierarchy is only allowed on a main thread."); return; } - Level::ScenesLock.Lock(); - // Unlink from the old one if (_parent) { @@ -107,8 +105,6 @@ void Script::SetParent(Actor* value, bool canBreakPrefabLink) _parent->Scripts.Add(this); } - Level::ScenesLock.Unlock(); - // Break prefab link for prefab instance objects if (HasPrefabLink() && IsDuringPlay() && canBreakPrefabLink) { @@ -137,7 +133,7 @@ void Script::SetParent(Actor* value, bool canBreakPrefabLink) Enable(); } } - else if (!previous && value->IsDuringPlay() && value->IsActiveInHierarchy() && GetEnabled()) + else if (!previous && value && value->IsDuringPlay() && value->IsActiveInHierarchy() && GetEnabled()) { // Call enable when script is added to actor (previous actor was null) Enable();