diff --git a/Source/Editor/Modules/SceneEditingModule.cs b/Source/Editor/Modules/SceneEditingModule.cs
index 3e47fa5bd..f8c15acbf 100644
--- a/Source/Editor/Modules/SceneEditingModule.cs
+++ b/Source/Editor/Modules/SceneEditingModule.cs
@@ -310,8 +310,9 @@ namespace FlaxEditor.Modules
///
/// The actor.
/// The parent actor. Set null as default.
+ /// The order under the parent to put the spawned actor.
/// True if automatically select the spawned actor, otherwise false.
- public void Spawn(Actor actor, Actor parent = null, bool autoSelect = true)
+ public void Spawn(Actor actor, Actor parent = null, int orderInParent = -1, bool autoSelect = true)
{
bool isPlayMode = Editor.StateMachine.IsPlayMode;
@@ -323,6 +324,10 @@ namespace FlaxEditor.Modules
// Add it
Level.SpawnActor(actor, parent);
+ // Set order if given
+ if (orderInParent != -1)
+ actor.OrderInParent = orderInParent;
+
// Peek spawned node
var actorNode = Editor.Instance.Scene.GetActorNode(actor);
if (actorNode == null)
@@ -568,7 +573,7 @@ namespace FlaxEditor.Modules
{
Position = center,
};
- Editor.SceneEditing.Spawn(parent, null, false);
+ Editor.SceneEditing.Spawn(parent, null, -1, false);
using (new UndoMultiBlock(Undo, actors, "Reparent actors"))
{
for (int i = 0; i < selection.Count; i++)
diff --git a/Source/Editor/Modules/SceneModule.cs b/Source/Editor/Modules/SceneModule.cs
index ad7d574fd..56c420964 100644
--- a/Source/Editor/Modules/SceneModule.cs
+++ b/Source/Editor/Modules/SceneModule.cs
@@ -32,9 +32,9 @@ namespace FlaxEditor.Modules
}
///
- public override void Spawn(Actor actor, Actor parent)
+ public override void Spawn(Actor actor, Actor parent, int orderInParent = -1)
{
- _editor.SceneEditing.Spawn(actor, parent);
+ _editor.SceneEditing.Spawn(actor, parent, orderInParent);
}
///
diff --git a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs
index d27f92f73..bf3f4b830 100644
--- a/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs
+++ b/Source/Editor/SceneGraph/GUI/ActorTreeNode.cs
@@ -690,9 +690,8 @@ namespace FlaxEditor.SceneGraph.GUI
if (_dragAssets.Objects[i] is not PrefabItem)
actor.Transform = Transform.Identity;
var previousTrans = actor.Transform;
- ActorNode.Root.Spawn(actor, spawnParent);
+ ActorNode.Root.Spawn(actor, spawnParent, newOrder);
actor.LocalTransform = previousTrans;
- actor.OrderInParent = newOrder;
}
result = DragDropEffect.Move;
}
@@ -710,8 +709,7 @@ namespace FlaxEditor.SceneGraph.GUI
}
actor.StaticFlags = newParent.StaticFlags;
actor.Name = item.Name;
- ActorNode.Root.Spawn(actor, newParent);
- actor.OrderInParent = newOrder;
+ ActorNode.Root.Spawn(actor, newParent, newOrder);
}
result = DragDropEffect.Move;
}
@@ -733,8 +731,7 @@ namespace FlaxEditor.SceneGraph.GUI
StaticFlags = newParent.StaticFlags,
Name = item.Name,
};
- ActorNode.Root.Spawn(uiControl, newParent);
- uiControl.OrderInParent = newOrder;
+ ActorNode.Root.Spawn(uiControl, newParent, newOrder);
}
result = DragDropEffect.Move;
}
@@ -761,8 +758,7 @@ namespace FlaxEditor.SceneGraph.GUI
actor.StaticFlags = spawnParent.StaticFlags;
actor.Name = actorType.Name;
actor.Transform = spawnParent.Transform;
- ActorNode.Root.Spawn(actor, spawnParent);
- actor.OrderInParent = newOrder;
+ ActorNode.Root.Spawn(actor, spawnParent, newOrder);
}
else if (scriptType != ScriptType.Null)
{
diff --git a/Source/Editor/SceneGraph/RootNode.cs b/Source/Editor/SceneGraph/RootNode.cs
index 31aaae855..07c2ed3bf 100644
--- a/Source/Editor/SceneGraph/RootNode.cs
+++ b/Source/Editor/SceneGraph/RootNode.cs
@@ -159,7 +159,7 @@ namespace FlaxEditor.SceneGraph
///
/// The actor.
/// The parent.
- public abstract void Spawn(Actor actor, Actor parent);
+ public abstract void Spawn(Actor actor, Actor parent, int orderInParent = -1);
///
/// Gets the undo.
diff --git a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs
index 0cfc2dd78..d1672b042 100644
--- a/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs
+++ b/Source/Editor/Windows/Assets/PrefabWindow.Hierarchy.cs
@@ -32,9 +32,9 @@ namespace FlaxEditor.Windows.Assets
}
///
- public override void Spawn(Actor actor, Actor parent)
+ public override void Spawn(Actor actor, Actor parent, int orderInParent)
{
- _window.Spawn(actor, parent);
+ _window.Spawn(actor, parent, orderInParent);
}
///
@@ -486,7 +486,8 @@ namespace FlaxEditor.Windows.Assets
///
/// The actor.
/// The parent.
- public void Spawn(Actor actor, Actor parent)
+ /// The order of the actor under the parent.
+ public void Spawn(Actor actor, Actor parent, int orderInParent = -1)
{
if (actor == null)
throw new ArgumentNullException(nameof(actor));
@@ -494,6 +495,10 @@ namespace FlaxEditor.Windows.Assets
// Link it
actor.Parent = parent ?? throw new ArgumentNullException(nameof(parent));
+ // Set order in parent
+ if (orderInParent != -1)
+ actor.OrderInParent = orderInParent;
+
// Peek spawned node
var actorNode = SceneGraphFactory.FindNode(actor.ID) as ActorNode ?? SceneGraphFactory.BuildActorNode(actor);
if (actorNode == null)