diff --git a/Engine/src/ECS/Entity/Store/NodeTree.cs b/Engine/src/ECS/Entity/Store/NodeTree.cs index 0b062cfd1..c562deb73 100644 --- a/Engine/src/ECS/Entity/Store/NodeTree.cs +++ b/Engine/src/ECS/Entity/Store/NodeTree.cs @@ -169,7 +169,8 @@ internal void InsertChild (int parentId, int childId, int childIndex) goto InsertNode; } // case: entity with given id is already a child of this entity => move child - curIndex = GetChildIndex(curParentEntity, childId); + var childIds = GetChildIds(curParentEntity); + curIndex = childIds.LastIndexOf(childId); // enable O(1) if childIndex == last child if (curIndex == childIndex) { // case: child entity is already at the requested childIndex return; @@ -215,7 +216,7 @@ private int RemoveChildNode (int parentId, int childId) var parent = new Entity(this, parentId); ref var treeNode = ref GetTreeNodeRef(parent); var childIds = treeNode.GetChildIds(this); - int index = childIds.IndexOf(childId); + int index = childIds.LastIndexOf(childId); // enable O(1) if childId == last child if (index != -1) { treeNode.childIds.RemoveAt(index, extension.childHeap, keepOrder: true); return index; diff --git a/Engine/src/Tests/ECS/Entity/Test_Entity_Tree.cs b/Engine/src/Tests/ECS/Entity/Test_Entity_Tree.cs index 571856263..212da09dc 100644 --- a/Engine/src/Tests/ECS/Entity/Test_Entity_Tree.cs +++ b/Engine/src/Tests/ECS/Entity/Test_Entity_Tree.cs @@ -441,7 +441,7 @@ public static void Test_Entity_Tree_TreeNode() public static void Test_Entity_Tree_Allocation() { int count = 10; // 2000 - // Test_Entity_Tree_Allocation - count: 2000 entities: 4002001 duration: 486 ms + // Test_Entity_Tree_Allocation - count: 2000 entities: 4002001 duration: 202 ms var store = new EntityStore(); var root = store.CreateEntity(1); var type = store.GetArchetype(default);