Instantiating a Button node to a parent works, but stops instantiating after several instances.

Godot Version

4.2.2(stable)

Question

func offer_calls(calls_to_offer,player):
	var parent = get_node("HBoxContainer/"+str(player))
	var label = Label.new()
	label.text = player
	parent.add_child(label)

	for call1 in calls_to_offer:
		var button = Button.new()
		button.text = call1
		parent.add_child(button)
		button.pressed.connect(self.call_button_pressed.bind(button))


func clear_call_buttons():
	for player in $"../Backend".get_node("RoundData").player_list:
		var parent = get_node("HBoxContainer/"+str(player))
		var children = parent.get_children()
		for child in children:
			if child == Label:
				continue
			child.queue_free()

This code is functional. Using existing parents in the scene, a label and number of buttons will be instantiated as children of 1 parent. Then after a button is pressed, the clear_call_button() func is called, freeing these buttons.

The process works as intended, instantiating and clearing the buttons, and then suddenly it will reach a point where the buttons should be instantiated, but they simply are not.
No error is thrown, no crash occurs, it just works until it doesn’t.

Any thoughts? Thank you for any help you may have.

Have you tried throwing in some print statements to see what happens each time it tries to instance a button?

Yep, I’ve debugged pretty heavily, tried instantiating in different ways, made sure the node is readied before it attempts instantiation. But every time it just gets to a point where it should instantiate, it passes the code where it should instantiate, but it does not add the child.

So the reason I ask the forum is because I wonder if it’s an engine bug?
There’s no error or anything, it just fails entirely.

if child == Label:
I don’t think it is related to your issue but does this actually work?
Shouldn’t this be
if child is Label:

After a quick test using == does not work and you must use is

2 Likes