0 votes

Hi,

I know I can check the node parameter Node.visible, but this is useless, if one of the parent nodes becomes invisible. Then all childs are invisivle too, but the flag .visible remains true.

Thanks!

in Engine by (65 points)

edited , now it works fine

2 Answers

+1 vote
Best answer

Thanks. But I found an other solution. There is a method .is_visible_in_tree() for every node, that shows the current visibility!

by (65 points)
0 votes
func _ready() -> void:
    # connecting signal and adding nodes as extra arguments so we can check if they are visible
    var _ok = get_child(0).connect('visibility_changed', self, '_on_visibility_changed', [[get_child(0)]])
    # child node connected as [ node, node.parent, parent.parent , ....]
    _ok = get_child(0).get_child(0).connect('visibility_changed', self, '_on_visibility_changed', [[get_child(0).get_child(0), get_child(0),]])



func _on_visibility_changed(nodes : Array):
    var visibility = true
    # check nodes from child to parent and update visibility
    for node in nodes:
        # if any node is hidden it will stop and changes visibility to false
        if node == null: return
        if !node.visible:
            visibility = node.visible
            break
    print( "%s visibility = %s" % [nodes[0].name, visibility])
by (272 points)
edited by

how I answer to a post?

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 webmaster@godotengine.org with your username.