0 votes

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")
in Engine by (390 points)

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")

The script is on the button, right?

1 Answer

0 votes

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')
by (272 points)
edited by
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.