EditorInterface
retrieved from EditorPlugin
or EditorScript
allows to fetch selected nodes via special EditorSelection
object.
EditorSelection
has selection_changed
signal that you can use to check whether any nodes are selected in the scene tree dock. In order to connect to selection_changed
signal:
var eds = get_editor_interface().get_selection()
func _enter_tree():
# Plugin initialization, etc
eds.connect("selection_changed", self, "_on_selection_changed")
Now you can handle it in a callback, for instance:
func _on_selection_changed():
# Returns an array of selected nodes
var selected = eds.get_selected_nodes()
if not selected.empty():
# Always pick first node in selection
var selected_node = selected[0]
This works in Godot 3.1.