Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow node visibility to work with custom user-provided node types #8812

Closed
aaronfranke opened this issue Jan 6, 2024 · 3 comments
Closed
Milestone

Comments

@aaronfranke
Copy link
Member

Describe the project you are working on

I am working on extending Godot with custom node types. Just slowly over time when I have time, as I can't dedicate a lot of time to this. But I'd like to create Node4D and NodeH3D (Hyperbolic 3D) during the 2020s. I have already made the base Node4D node and the supporting math classes. Nothing inherits it yet, but it exists in 4D, sitting there doing nothing.

Describe the problem or limitation you are having in your project

Godot's 2D and 3D nodes have a visibility system, with is_visible, set_visible, and is_visible_in_tree functions, and the visibility_changed signal. An eyeball appears in the scene tree that shows the state and allows clicking to change it.

It is not possible for custom node types to use the eyeball. Godot's editor code is hard-coded for a few node types.

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Change the code to be more generic so that it will work with any node type that implements the visibility API.

Screenshot 2023-12-17 at 10 40 47 AM

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

godotengine/godot#86268

Basically, use if (p_node->has_method("is_visible") && p_node->has_method("set_visible") && p_node->has_signal("visibility_changed")) { instead of if (p_node->is_class("CanvasItem")) {, } else if (p_node->is_class("CanvasLayer") || p_node->is_class("Window")) {, } else if (p_node->is_class("Node3D")) {. This also simplifies the code quite a lot because it avoids unnecessary repetition.

If this enhancement will not be used often, can it be worked around with a few lines of script?

No, this is behavior the scene tree editor's C++ code, this can't be modified by GDScript.

Is there a reason why this should be core and not an add-on in the asset library?

The scene tree editor's eyeball feature is already a part of the Godot editor.

@caimantilla
Copy link

caimantilla commented Mar 25, 2024

I feel like a virtual method on the node class that determines how editor visibility works would be better. In my case, I want to adjust the visibility of elements of a grid-based game, where everything is made up of basic nodes. Either way, it allows more custom implementations with less headache for the scene tree editor.
Something like virtual bool _has_scene_editor_visibility_button(), virtual bool _get_scene_editor_visibility_button_state(), and virtual bool _scene_editor_visibility_button_state_updated. Similar to the configuration warning methods.
I think I'll try my hand at it...
Actually, if there's an enum for the button state that's better, as more states are required to represent a node being visible but not in the tree (so greyed out).

@caimantilla
Copy link

caimantilla commented Mar 25, 2024

Wait, I'm looking at master and this is already implemented... lol ignore that. this can be closed.

@fire
Copy link
Member

fire commented Mar 25, 2024

Fixed by: godotengine/godot#86268.

@fire fire closed this as completed Mar 25, 2024
@akien-mga akien-mga added this to the 4.3 milestone Mar 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants