From c2afe0b6b2806b68cd9ff70f2af7e0c305fe72e0 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 29 Apr 2021 15:22:10 +0200 Subject: [PATCH] Fix synchronizing ActorTreeNode order after actor duplicate #487 --- Source/Editor/SceneGraph/ActorNode.cs | 4 ++-- Source/Editor/SceneGraph/GUI/ActorTreeNode.cs | 4 ++++ Source/Editor/SceneGraph/SceneGraphNode.cs | 13 ++----------- Source/Engine/Level/Actor.cpp | 3 +-- Source/Engine/UI/GUI/ContainerControl.cs | 2 ++ 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/Source/Editor/SceneGraph/ActorNode.cs b/Source/Editor/SceneGraph/ActorNode.cs index 017cff3bf..3542feb03 100644 --- a/Source/Editor/SceneGraph/ActorNode.cs +++ b/Source/Editor/SceneGraph/ActorNode.cs @@ -194,7 +194,7 @@ namespace FlaxEditor.SceneGraph { get { - var scene = _actor.Scene; + var scene = _actor ? _actor.Scene : null; return scene != null ? SceneGraphFactory.FindNode(scene.ID) as SceneNode : null; } } @@ -235,7 +235,6 @@ namespace FlaxEditor.SceneGraph { if (!(value is ActorNode)) throw new InvalidOperationException("ActorNode can have only ActorNode as a parent node."); - base.ParentNode = value; } } @@ -299,6 +298,7 @@ namespace FlaxEditor.SceneGraph // (eg. we build new node for spawned actor and link it to the game) if (_treeNode.Parent != null && !_treeNode.Parent.IsLayoutLocked) { + _treeNode.IndexInParent = _actor.OrderInParent; _treeNode.Parent.SortChildren(); // Update UI diff --git a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs index 7b4b35ed1..2c050c2e3 100644 --- a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs +++ b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs @@ -86,6 +86,10 @@ namespace FlaxEditor.SceneGraph.GUI } parent.SortChildren(); } + else if (Actor) + { + _orderInParent = Actor.OrderInParent; + } } internal void OnNameChanged() diff --git a/Source/Editor/SceneGraph/SceneGraphNode.cs b/Source/Editor/SceneGraph/SceneGraphNode.cs index 6cf83647a..bc8fe84aa 100644 --- a/Source/Editor/SceneGraph/SceneGraphNode.cs +++ b/Source/Editor/SceneGraph/SceneGraphNode.cs @@ -112,18 +112,9 @@ namespace FlaxEditor.SceneGraph { if (parentNode != value) { - if (parentNode != null) - { - parentNode.ChildNodes.Remove(this); - } - + parentNode?.ChildNodes.Remove(this); parentNode = value; - - if (parentNode != null) - { - parentNode.ChildNodes.Add(this); - } - + parentNode?.ChildNodes.Add(this); OnParentChanged(); } } diff --git a/Source/Engine/Level/Actor.cpp b/Source/Engine/Level/Actor.cpp index ef5b2a554..21e2ae050 100644 --- a/Source/Engine/Level/Actor.cpp +++ b/Source/Engine/Level/Actor.cpp @@ -1597,7 +1597,7 @@ bool Actor::FromBytes(const Span& data, Array& output, ISerializeM // Order in parent int32 orderInParent; stream.ReadInt32(&orderInParent); - order.At(i) = orderInParent; + order[i] = orderInParent; // Load JSON rapidjson_flax::Document document; @@ -1637,7 +1637,6 @@ bool Actor::FromBytes(const Span& data, Array& output, ISerializeM // Order in parent int32 orderInParent; stream.ReadInt32(&orderInParent); - order.Add(orderInParent); // Load JSON rapidjson_flax::Document document; diff --git a/Source/Engine/UI/GUI/ContainerControl.cs b/Source/Engine/UI/GUI/ContainerControl.cs index 57d2fb528..3519469a2 100644 --- a/Source/Engine/UI/GUI/ContainerControl.cs +++ b/Source/Engine/UI/GUI/ContainerControl.cs @@ -249,6 +249,8 @@ namespace FlaxEngine.GUI internal void ChangeChildIndex(Control child, int newIndex) { int oldIndex = _children.IndexOf(child); + if (oldIndex == newIndex) + return; _children.RemoveAt(oldIndex); // Check if index is invalid