diff --git a/Source/Editor/Modules/SceneEditingModule.cs b/Source/Editor/Modules/SceneEditingModule.cs
index 970ca8e99..35b85bfa8 100644
--- a/Source/Editor/Modules/SceneEditingModule.cs
+++ b/Source/Editor/Modules/SceneEditingModule.cs
@@ -534,6 +534,41 @@ namespace FlaxEditor.Modules
Delete();
}
+ ///
+ /// Create parent for selected actors.
+ ///
+ public void CreateParentForSelectedActors()
+ {
+ Actor actor = new EmptyActor();
+ Editor.SceneEditing.Spawn(actor, null, false);
+ List selection = Editor.SceneEditing.Selection;
+ var actors = selection.Where(x => x is ActorNode).Select(x => ((ActorNode)x).Actor);
+ using (new UndoMultiBlock(Undo, actors, "Reparent actors"))
+ {
+ for (int i = 0; i < selection.Count; i++)
+ {
+ if (selection[i] is ActorNode node)
+ {
+ if (node.ParentNode != node.ParentScene) // If parent node is not a scene
+ {
+ if (selection.Contains(node.ParentNode))
+ {
+ return; // If parent and child nodes selected together, don't touch child nodes
+ }
+
+ // Put created node as child of the Parent Node of node
+ int parentOrder = node.Actor.OrderInParent;
+ actor.Parent = node.Actor.Parent;
+ actor.OrderInParent = parentOrder;
+ }
+ node.Actor.Parent = actor;
+ }
+ }
+ }
+ Editor.SceneEditing.Select(actor);
+ Editor.Scene.GetActorNode(actor).TreeNode.StartRenaming(Editor.Windows.SceneWin, Editor.Windows.SceneWin.SceneTreePanel);
+ }
+
///
/// Duplicates the selected objects. Supports undo/redo.
///
diff --git a/Source/Editor/Modules/UIModule.cs b/Source/Editor/Modules/UIModule.cs
index 3386d411c..4537d732e 100644
--- a/Source/Editor/Modules/UIModule.cs
+++ b/Source/Editor/Modules/UIModule.cs
@@ -50,6 +50,7 @@ namespace FlaxEditor.Modules
private ContextMenuButton _menuEditCut;
private ContextMenuButton _menuEditCopy;
private ContextMenuButton _menuEditPaste;
+ private ContextMenuButton _menuCreateParentForSelectedActors;
private ContextMenuButton _menuEditDelete;
private ContextMenuButton _menuEditDuplicate;
private ContextMenuButton _menuEditSelectAll;
@@ -548,11 +549,11 @@ namespace FlaxEditor.Modules
_menuEditCut = cm.AddButton("Cut", inputOptions.Cut, Editor.SceneEditing.Cut);
_menuEditCopy = cm.AddButton("Copy", inputOptions.Copy, Editor.SceneEditing.Copy);
_menuEditPaste = cm.AddButton("Paste", inputOptions.Paste, Editor.SceneEditing.Paste);
- cm.AddSeparator();
_menuEditDelete = cm.AddButton("Delete", inputOptions.Delete, Editor.SceneEditing.Delete);
_menuEditDuplicate = cm.AddButton("Duplicate", inputOptions.Duplicate, Editor.SceneEditing.Duplicate);
cm.AddSeparator();
_menuEditSelectAll = cm.AddButton("Select all", inputOptions.SelectAll, Editor.SceneEditing.SelectAllScenes);
+ _menuCreateParentForSelectedActors = cm.AddButton("Create parent for selected actors", Editor.SceneEditing.CreateParentForSelectedActors);
_menuEditFind = cm.AddButton("Find", inputOptions.Search, Editor.Windows.SceneWin.Search);
cm.AddSeparator();
cm.AddButton("Game Settings", () =>
@@ -858,6 +859,7 @@ namespace FlaxEditor.Modules
_menuEditCut.Enabled = hasSthSelected;
_menuEditCopy.Enabled = hasSthSelected;
_menuEditPaste.Enabled = canEditScene;
+ _menuCreateParentForSelectedActors.Enabled = canEditScene && hasSthSelected;
_menuEditDelete.Enabled = hasSthSelected;
_menuEditDuplicate.Enabled = hasSthSelected;
_menuEditSelectAll.Enabled = Level.IsAnySceneLoaded;
diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs
index 0c8e0f283..abad36829 100644
--- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs
+++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs
@@ -132,10 +132,13 @@ namespace FlaxEditor.Windows
b = contextMenu.AddButton("Cut", inputOptions.Cut, Editor.SceneEditing.Cut);
b.Enabled = canEditScene;
- // Prefab options
+ // Create option
contextMenu.AddSeparator();
+ b = contextMenu.AddButton("Create parent for selected actors", Editor.SceneEditing.CreateParentForSelectedActors);
+ b.Enabled = canEditScene && hasSthSelected;
+
b = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab);
b.Enabled = isSingleActorSelected &&
((ActorNode)Editor.SceneEditing.Selection[0]).CanCreatePrefab &&
diff --git a/Source/Editor/Windows/SceneTreeWindow.cs b/Source/Editor/Windows/SceneTreeWindow.cs
index 97bf85b35..1eb80c9ea 100644
--- a/Source/Editor/Windows/SceneTreeWindow.cs
+++ b/Source/Editor/Windows/SceneTreeWindow.cs
@@ -24,6 +24,8 @@ namespace FlaxEditor.Windows
///
public partial class SceneTreeWindow : SceneEditorWindow
{
+ public Panel SceneTreePanel => _sceneTreePanel;
+
private TextBox _searchBox;
private Tree _tree;
private Panel _sceneTreePanel;