5
\$\begingroup\$

This a follow-up question of this one

I want to disconnect multiple signals before using queue_free().

In docs we have:

void disconnect ( String signal, Object target, String method )

Is it possible to disconnect all signals of an emitter without using the names of the signals or methods involved?

\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

You can get the list of signals with get_signal_list:

var signals = node.get_signal_list();
for cur_signal in signals:
    print(cur_signal.name);

Then you can get the list of connections for each one with get_signal_connection_list to find where those signals are connected to:

var signals = node.get_signal_list();
for cur_signal in signals:
    var conns = node.get_signal_connection_list(cur_signal.name);
    for cur_conn in conns:
        print(cur_conn.signal);
        print(cur_conn.target);
        print(cur_conn.method);

That is the information of signal connections that connect from an object. Which you need to disconnect them:

node.disconnect(cur_conn.signal, cur_conn.target, cur_conn.method)

On the other hand, if you want the information of signal connections that connect to an object, you can use get_incoming_connections instead:

var conns = node.get_incoming_connections();
for cur_conn in conns:
    print(cur_conn.signal_name);
    print(cur_conn.source);
    print(cur_conn.method_name);

Disconnecting them would be:

cur_conn.source.disconnect(cur_conn.signal_name, node, cur_conn.method_name)
\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .