Disconnect signals from an instantiated element

Godot Version

4.2

Question

` Hi guys, I was wondering, when an instantiated node is freed, what happens to the signals connected to its parent? Are they all disconnected automatically, or do I need to disconnect them before freeing the node

This is the code where I am free and connecting the signals

func _set_heroes_grid() -> void:
# get the current heroes in the grid by his index
	var grid_sizing = 4;
	var new_heroes = heroes_pool.slice(index * grid_sizing, grid_sizing + (index * grid_sizing))
	var grid = $GridChampions
# check if exist heroes on the stack and clean
	var current_heroes = grid.get_child_count()
	
	if current_heroes > 0:
		var children = grid.get_children()
		for hero in children:
			hero.free()
	
# create and instance the heroes
	for hero in new_heroes:
		var instance = _hero_avatar.instantiate() as HeroAvatar
		instance.hero_data = hero
		grid.add_child(instance)
		instance.connect('pressed', _open_character_details)

`

Yes they are removed automatically if you use “queue_free”. If you use “free” you have to remove them yourself i believe

1 Like

This is what I was looking for, thank you! I’m going to change free to queue_free

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.