Godot Version
v4.4.1.stable.official [49a5bc7b6]
Question
Trying to comprehend how NodeGizmos work in general, but I would like to be able to access the selected node’s gizmo data from an EditorPlugin. Is that even possible? Any in depth tutorials about gizmos other than the godot documentation? Thanks
If it helps, you can get selected nodes’ gizmos like this:
# Get the selected nodes (Array[Node])
var nodes = EditorInterface.get_selection().get_selected_nodes()
for node in nodes:
if node is Node3D:
var gizmos = node.get_gizmos()
See EditorInterface.get_selection()
, EditorSelection.get_selected_nodes()
, and Node3D.get_gizmos()
.
EDIT: Submitted it as a bug. The method Node3D.get_gizmos() does not get the gizmo for Node3D class, but only subclass nodes. · Issue #108296 · godotengine/godot · GitHub
Strangely enough returns an empty array if you select Node3D. But it returns the gizmos for MeshInstance3D and others. Am I doing anything wrong? Thanks
Here is the plugin.gd code:
@tool
extends EditorPlugin
var selected_node:Node3D
func _enter_tree():
# Connect to the selection_changed signal.
EditorInterface.get_selection().connect("selection_changed", Callable(self, "_on_selection_changed"))
func _exit_tree():
# Disconnect the signal when the plugin is removed.
EditorInterface.get_selection().disconnect("selection_changed", Callable(self, "_on_selection_changed"))
func _enable_plugin():
pass
func _disable_plugin():
pass
func _get_plugin_name():
pass
func _on_selection_changed():
var selected_nodes = EditorInterface.get_selection().get_selected_nodes()
# Check if any nodes are selected.
if selected_nodes.size() > 0:
# Get the first selected node.
print("\n\nClass:", selected_nodes[0].get_class())
#print(get_main_screen())
var gizmos:Array[Node3DGizmo]
var gizmo: Node3DGizmo
for node in selected_nodes:
#if node is Node3D:
gizmos = node.get_gizmos()
print("Gizmos: ",gizmos)
plugin.cfg
[plugin]
name="Gizmo"
description="Gizmo"
author="wyattbiker"
version="1.0-BETA"
script="plugin.gd"
1 Like