how can i disabled focus_mode on all my child node?

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

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
:bust_in_silhouette: Reply From: Wakatta

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

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

potatobanana | 2021-04-04 19:52

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():

Wakatta | 2021-04-04 20:14

cannoli look delicious, but never see holy cannoli :slight_smile:

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

potatobanana | 2021-04-04 20:53

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

Wakatta | 2021-04-04 21:34