Random beginner-question: Node as child of Node2D stays visible when parent turns invisible

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

Hi everyone,

turning a Node2D invisible does not apply to it’s base-class-Node children – these stay visible. Changing their type to Node2D then makes them become invisible along with the parent.

I see that a base-Node cannot be turned invisibe, but having some buried deep within my scene-tree, I wonder if it wouldn’t be practical to have them adopt the behaviour of their parent in such a case.

Is there a reason for this behaviour? And can I somehow make a Node get invisible in such a case as well?

:bust_in_silhouette: Reply From: jgodfrey

The Inheritance chain for a Node2D looks like this:

Node2D < CanvasItem < Node < Object

The visibility property is on the CanvasItem. So, the Node2D has that property because it inherits from CanvasItem. A Node does not have a visibility property, and therefore, it’s not possible to set such a property there.

Additionally, a Node item by itself is not visible in-game. That is, there’s nothing rendered for it by default. Maybe a description of your scene tree is in order here, specifically related to these “visible” nodes.

jgodfrey | 2020-12-09 21:44

Ah, maybe I see what you’re getting at. So, in a structure like this:


If you turn off visibility of Sprite1, then Sprite2 is also made invisible.

However, with this structure:


Turning off the visibility of Sprite1 does not impact the visibility of Sprite2.

Can you not just replace your nested Node references with CanvasItem or Node2D (for example)?

jgodfrey | 2020-12-09 21:52

Exactly this! Yes, changing the type from Node to Node2D works.

This leaves me wondering: are there cases when a Node should be preferred over Node2D? Why not just stick to Node2D and “enjoy more features” from the start?

Just changing the type appears somewhat harsh to me - couldn’t this lead to unexpected issues?

pferft | 2020-12-10 08:38