Fix using Scripts in async
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user