diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index 30ca06daf..ce3bcdb65 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -948,11 +948,19 @@ void Actor::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier) const auto parent = Scripting::FindObject(parentId); if (_parent != parent) { - if (_parent) - _parent->Children.RemoveKeepOrder(this); - _parent = parent; - if (_parent) - _parent->Children.Add(this); + if (IsDuringPlay()) + { + SetParent(parent, false, false); + } + else + { + if (_parent) + _parent->Children.RemoveKeepOrder(this); + _parent = parent; + if (_parent) + _parent->Children.Add(this); + OnParentChanged(); + } } else if (!parent && parentId.IsValid()) { @@ -1044,6 +1052,10 @@ void Actor::OnDisable() } } +void Actor::OnParentChanged() +{ +} + void Actor::OnTransformChanged() { ASSERT_LOW_LAYER(!_localTransform.IsNanOrInfinity()); diff --git a/Source/Engine/Level/Actor.h b/Source/Engine/Level/Actor.h index da08bc498..6416fd33a 100644 --- a/Source/Engine/Level/Actor.h +++ b/Source/Engine/Level/Actor.h @@ -918,9 +918,7 @@ public: /// /// Called when actor parent gets changed. /// - virtual void OnParentChanged() - { - } + virtual void OnParentChanged(); /// /// Called when actor transform gets changed. diff --git a/Source/Engine/Level/Actors/BoneSocket.cpp b/Source/Engine/Level/Actors/BoneSocket.cpp index 7673781ff..028b1c507 100644 --- a/Source/Engine/Level/Actors/BoneSocket.cpp +++ b/Source/Engine/Level/Actors/BoneSocket.cpp @@ -104,6 +104,9 @@ void BoneSocket::OnParentChanged() { // Base Actor::OnParentChanged(); + + if (!IsDuringPlay()) + return; _index = -1; UpdateTransformation(); diff --git a/Source/Engine/Level/Actors/BoxBrush.cpp b/Source/Engine/Level/Actors/BoxBrush.cpp index ca38c103d..f02dd5bd3 100644 --- a/Source/Engine/Level/Actors/BoxBrush.cpp +++ b/Source/Engine/Level/Actors/BoxBrush.cpp @@ -272,6 +272,9 @@ void BoxBrush::OnParentChanged() { // Base Actor::OnParentChanged(); + + if (!IsDuringPlay()) + return; // Fire event OnBrushModified(); diff --git a/Source/Engine/Physics/Joints/Joint.cpp b/Source/Engine/Physics/Joints/Joint.cpp index cda249d71..56c5c1b32 100644 --- a/Source/Engine/Physics/Joints/Joint.cpp +++ b/Source/Engine/Physics/Joints/Joint.cpp @@ -295,6 +295,9 @@ void Joint::OnParentChanged() // Base Actor::OnParentChanged(); + if (!IsDuringPlay()) + return; + // Check reparenting Joint case const auto parent = dynamic_cast(GetParent()); if (parent == nullptr) diff --git a/Source/Engine/UI/UIControl.cpp b/Source/Engine/UI/UIControl.cpp index 131c04298..33fe8a93b 100644 --- a/Source/Engine/UI/UIControl.cpp +++ b/Source/Engine/UI/UIControl.cpp @@ -156,6 +156,9 @@ void UIControl::OnParentChanged() // Base Actor::OnParentChanged(); + if (!IsDuringPlay()) + return; + UICONTROL_INVOKE(ParentChanged); }