Open allenwp opened 1 year ago
This proposal is based off of the initial discussion.
This proposal is a relatively simple solution that could be implemented in the short term and may be superseded by or implemented differently in the long term by #7213.
I have taken a look at the editor code for centering/focusing on selected nodes and found that I am not experienced enough with the editor codebase to make a PR for this feature, so I'm looking for someone else to take the reigns on implementing this.
In case it's helpful to those who use a custom build of the editor and are looking for a stop-gap solution until this feature is implemented, here's my "good enough solution" that allows me to focus on the selected remote Node3D
. Unfortunately, this code only really works if the Node3D
's position
equals its gloabl_position
. I find this is better than nothing and at least lets me get my editor camera into the approximate area of the level that I want to view with the project camera override:
Add this to editor/plugins/node_3d_editor_plugin.cpp
:
#include "editor/editor_interface.h"
#include "editor/debugger/editor_debugger_inspector.h"
void Node3DEditor::focus_3d_remote_inspector_selection() {
Object *edited_obj = EditorInterface::get_singleton()->get_inspector()->get_edited_object();
EditorDebuggerRemoteObject *remoteObj = Object::cast_to<EditorDebuggerRemoteObject>(edited_obj);
if (remoteObj) {
Variant variant = remoteObj->get_variant("position");
if (variant && variant.get_type() == Variant::Type::VECTOR3) {
for (int i = 0; i < Node3DEditor::VIEWPORTS_COUNT; i++) {
Node3DEditorViewport *vp = Node3DEditor::get_singleton()->get_editor_viewport(i);
vp->cursor.pos = variant;
}
}
}
}
// Add this line to void Node3DEditor::_bind_methods():
ClassDB::bind_static_method("Node3DEditor", D_METHOD("focus_3d_remote_inspector_selection"), &Node3DEditor::focus_3d_remote_inspector_selection);
Add this to the public
section of Node3DEditor in editor/plugins/node_3d_editor_plugin.h
:
static void focus_3d_remote_inspector_selection();
Add this to void register_editor_types()
of editor/register_editor_types.cpp
ClassDB::register_abstract_class<Node3DEditor>();
After making these additions, you can make a plugin or some other type of @tool
that calls this static method:
Node3DEditor.focus_3d_remote_inspector_selection()
Describe the project you are working on
Any time I am using the Game workspace with "Override the in-game camera" enabled. Also, any time I want to bring my editor camera to be centered/focused the part of the world where my player node is.
Describe the problem or limitation you are having in your project
When enabling "Override the in-game camera" in Game workspace, I should be able to press F to focus selection on the remote node, similar to how I can do this in the 2D and 3D workspaces. Similar to the current 2D workspace behaviour, the camera that reacts to the F keyboard shortcut should be the one of the viewport that my mouse is hovering over.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
The Center View (a.k.a. Center Selection) and Focus Selection actions (pressing F) should center/focus on selected remote nodes, similar to how it focuses on selected local nodes. This should be the case for focusing the "Override the in-game camera" as well as focusing the 2D or 3D workspace cameras. Whichever viewport/game the mouse is hovering over when F is pressed should react.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Current behaviour:
Proposed behaviour:
Point 3 in the proposed behaviour also addresses a usability issue with selecting remote nodes: With the current behaviour, there is a discrepancy between the 2D/3D/Game workspaces (which only show the most recently selected local or remote node) and the inspector panel (which only shows the most recently selected node). With the proposed behaviour, this usability issue would no longer be a problem because the 2D/3D/Game workspaces would never show a different node than the inspector panel. This issue has become a minor issue with the implementation of the new Game workspace because the Game workspace can show the selected remote node; now one of the workspaces will show the node in the inspector, even if it is a remote node.
Changes to the Game workspace
When "override the in-game camera" and 3D selection are enabled, two new options would be added to the Game workspace menu to match 3D camera focus features:
When "override the in-game camera" and 2D selection are enabled, two new options would be added to the Game workspace menu to match 2D Camera feature:
If this enhancement will not be used often, can it be worked around with a few lines of script?
It will be used often.
Is there a reason why this should be core and not an add-on in the asset library?
This is core editor functionality.