How connect to connect the event "selection_changed" of EditorSelection

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Charles Woodhill
:warning: Old Version Published before Godot 3 was released.

im trying to bind to the “selection changed” event inside an editor plugin:

func _enter_tree():
    dock = preload("res://xxx.tscn").instance()
    dock.set_name("somename");
    add_control_to_dock( DOCK_SLOT_RIGHT_BL, dock)
    
    var s
    s = get_selection() // seems to work (no error msg)
    var arr = s.get_selected_nodes()  //seems to work (no error msg)
    connect("selection_changed",s,"selected_changed1") //error: described below

func selected_changed1():
...

the error i get when trying to connect to the event is:

ERROR: In Object of type "EditorPlugin": Attempt to connect nonexistent signal  "selection_changed" to method "EditorSelection.selected_changed1"

but in editor_data.cpp i find:

void EditorSelection::_bind_methods() {
     .....
ADD_SIGNAL(MethodInfo("selection_changed")); 
    .....

}

:bust_in_silhouette: Reply From: atze

This is how I do it in 2.1.2:

get_selection().connect("selection_changed", self, "_on_selection_changed")

This is correct. The reason is because “selection_changed” is a signal on the class EditorSelection.

EditorSelection — Godot Engine (stable) documentation in English

You get one with a call to ‘get_selection()’ inside the EditorPlugin.

avencherus | 2017-03-09 21:58

tnx for the really fast answer :slight_smile:

Charles Woodhill | 2017-03-10 13:35