Disconnecting signals: dealing with signals generated by parent

Godot Version

v4.3.beta2.official [b75f0485b]


I made a VBox container and put some buttons in it. In the _ready(): function of the container, I connect some button signals to some functions in the container. So far so good.

But then at one point I’m trying to disconnect all the signals that these children buttons have. First I retrieve all the buttons, then all their signals, and then I go through each signal, get the list of the incoming connections and disconnect them:

func disconnect_all_signals( B : Button ):
	var BSL # button signal list
	BSL = B.get_signal_list()
	# go through all signals
	for s in BSL :
		# signal's connections list
		var SCL
		SCL = B.get_signal_connection_list( s.name )
		# for each connection
		for c in SCL :
			c.signal.disconnect( c.callable )

The signals I connected through code (in _ready(): ) disconnect without problems using this method, but the problem is that VBox automatically generates some signal connections with children, for example “minimum size changed”.

When I try to disconnect everything from a signal automatically, these generated signals can’t be disconnected short of moving the child out of the parent, so when I try to disconnect everything I get tons of errors in the console like

E 0:00:11:0767 _disconnect: Attempt to disconnect a nonexistent connection from ‘btn_launch:<Button#33118225756>’. Signal: ‘visibility_changed’, callable: ‘Container::_child_minsize_changed’.

How do I skip these “automatically generated” signal connections when disconnecting signals from functions in order to avoid flooding the console with errors?

If you’re making the connections in the _ready() function, put the connections in a list to disconnect later. Essentially creating a whitelist of connection names you want to disconnect.

This solution will work in this particular case, but then I expect this question will pop up later again if I ever try to disconnect all signals using a loop like above (won’t work for these “automatically generated” type of signals)… Meanwhile I’ll mark this as solved, thank you! :raised_hands: