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
|
// Check if value won't change
|
||||||
if (_parent == value)
|
if (_parent == value)
|
||||||
return;
|
return;
|
||||||
if (!IsInMainThread())
|
if (IsDuringPlay() && !IsInMainThread())
|
||||||
{
|
{
|
||||||
LOG(Error, "Editing scene hierarchy is only allowed on a main thread.");
|
LOG(Error, "Editing scene hierarchy is only allowed on a main thread.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Level::ScenesLock.Lock();
|
|
||||||
|
|
||||||
// Unlink from the old one
|
// Unlink from the old one
|
||||||
if (_parent)
|
if (_parent)
|
||||||
{
|
{
|
||||||
@@ -107,8 +105,6 @@ void Script::SetParent(Actor* value, bool canBreakPrefabLink)
|
|||||||
_parent->Scripts.Add(this);
|
_parent->Scripts.Add(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
Level::ScenesLock.Unlock();
|
|
||||||
|
|
||||||
// Break prefab link for prefab instance objects
|
// Break prefab link for prefab instance objects
|
||||||
if (HasPrefabLink() && IsDuringPlay() && canBreakPrefabLink)
|
if (HasPrefabLink() && IsDuringPlay() && canBreakPrefabLink)
|
||||||
{
|
{
|
||||||
@@ -137,7 +133,7 @@ void Script::SetParent(Actor* value, bool canBreakPrefabLink)
|
|||||||
Enable();
|
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)
|
// Call enable when script is added to actor (previous actor was null)
|
||||||
Enable();
|
Enable();
|
||||||
|
|||||||
Reference in New Issue
Block a user