Get editor selection is hard!?

Godot Version

4.4.1

Question

how, why is this so hard?

I do ( as the doc says i think ) like this:

	if Input.is_key_pressed(KEY_ALT) and Input.is_key_pressed(KEY_R):
		var selected = EditorInterface.get_selection()
		if selected is Node3D or selected is MeshInstance3D or selected is StaticBody3D:
			print(selected)

the doc i’ve made this from is

directed from this quote on godot doc

But my very StaticBody3D is not being registered by the var selected = EditorInterface.get_selection()

It gives me this:
<EditorSelection#30819747236>

Which i can see is wrong since of course no object is called EditorSelection#30819747236
selected.name fails, and gives and error.

I¨m very confused by this. Anybody has any idea?

Thanks all for being a rubber duck. Fixed it by just trying out things. For posterity here is the solution

		var selected = EditorInterface.get_selection().get_transformable_selected_nodes()
		var selectedRoot = selected[0]

selectedRoot can be tampered with!

For reference get_selection returns a EditorSelection type, it’s a object for handling selections within the editor, not the actual selected object(s).

Of that EditorSelection type you can use get_selected_nodes or as you found get_transformable_selected_nodes().

var selector: EditorSelection = EditorInterface.get_selection()

var selected_nodes: Array[Node] = selector.get_selected_nodes()
for node in selected_nodes:
    print(node.name)

thanks. :slight_smile: