how to get child of my node? without child name?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By potatobanana

how to get child of my node? without child name?
for example i have
parent button
child label

how can i get child node?
i do like this and did’t work

func _on_Button5_pressed() -> void:
	for child in get_children():
		if child is Label:
			child.set_text("teesttts")

The code seems fine to me

But this might help debugging it

func _on_Button5_pressed() -> void:
    print("Pressed signal is detected")

    printt("Check if this have any children at all", get_children())
    for child in get_children():

        if child is Label:
             printt("If this isn't called, none of the child is a label")

             child.set_text("teesttts")

LoneDespair | 2021-02-23 17:33

The script is on the button, right?

exuin | 2021-02-23 17:52

:bust_in_silhouette: Reply From: Whalesstate

the code seems fine , try closing and reopening the scene and it should work
also you can use get_child(child_index) like get_child(0) will return the first child of the node

func _ready() -> void:
    connect('pressed', self, '_on_button_pressed')

func _on_button_pressed() -> void:
    print('pressed')
    for child in get_children():
    	if child is Label:
    		child.set_text('It Works')