0 votes

how can i disabled focus_mode on all my child node(button type)?
what i want to do is when i pause tree. i dont want focus on node that did't process at that time.
for example i want to disable focus all child(button type) of node "stats"
enter image description here

there other way than group all node child then disabled it like this?

func _on_pause_pressed() -> void:
    get_node("style").pause_mode =Node.PAUSE_MODE_PROCESS
    get_tree().paused = true
    for x in get_tree().get_nodes_in_group("stats_child"):
        x.focus_mode = 0
in Engine by (416 points)
edited by

1 Answer

+1 vote
Best answer

Is this for a toolScript or in Game?

func _on_pause_pressed() -> void:
    var style = get_node("style")
    style.pause_mode =Node.PAUSE_MODE_PROCESS
    get_tree().paused = true
    for child in style.get_children():
        if child.has_method("set_focus_mode"):
            child.focus_mode = 0
by (5,842 points)
selected by

thanks, base on my question you give me the right answer. in game.
but i just realize that what i want not just children of node, but i need everything under node, child, grandchild ,child of grandchild, basically node child and all sub they have.
enter image description here

Holy cannoli

Try this function.

func hereditary_marker(node):
    if node.has_method("set_focus_mode"):
        node.focus_mode = 0
    for child in node.get_children():

cannoli look delicious, but never see holy cannoli :)

thanks your function work, this code what they call recursion right?

It's a Canadian thing and There Cannoli Be One

this code what they call recursion right?

Correct but be wary of this power I've bestowed upon you as it usually results in stackoverflows

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 Frequently asked questions and 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 [email protected] with your username.