0 votes

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?

in Engine by (463 points)

1 Answer

0 votes
Best answer

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.

by (16,718 points)
selected by

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.

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

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?

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.