-
-
Notifications
You must be signed in to change notification settings - Fork 98
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
Add an annotation to only display property if node is root of current scene #10024
Comments
On one hand we already have other It is worth noting that with Hopefully somebody else can chime in on what is the best approach. |
Kinda feel like this fits more as an extension of #9842, at minimum they are related. |
I found #9842 when back when I was drafting this up; from there I found the much earlier #1056. They both certainly share the foundation of changing the visibility of properties based on specific criteria. The use case this proposal is targeting is standard enough that I think it would make sense to have it be more streamlined and intuitive than what a generic One of the authors in #9842 also states:
which makes it significantly harder, if not impossible, to implement Since we have an implementation of this behavior working, I think it'd make sense to use it for now. Perhaps in the future, if annotations are expanded to support runtime, this behavior could be adapted over to it. Some code from my implementation of this behavior could possibly also be used to facilitate more general hide/show behavior for variables in the inspector. |
I've always had the idea on the back of my head that if a |
I like the idea of Looks like proper access modifiers are being discussed at #641! As I skim through that thread, I don't see anyone saying they've actually taken the project on, but if someone did, then I think |
As an addendum, my described behavior is very similar to the addon Hide Private Properties which achieves this by filtering exported properties starting with " https://github.com/kenyoni-software/godot-addons/tree/main/addons/hide_private_properties |
Describe the project you are working on
A top-down 2D shooter, as well as a rhythm-centric turn-based RPG (although these specifics aren't relevant here)
Describe the problem or limitation you are having in your project
Before making a proposal, this feature idea was discussed here: #10017
I like to use
@export
ed properties on my scripts to link sub-nodes to them. For example, I might have a Player scene like this:With the following script, I can drag and drop the nodes into the property slots, and then access them in the Player script:
If I place this scene in another scene, those slots still take up space, despite the fact that they should be "fixed" at this level (if I want to change them, I'll go into the Player scene to do that).
Describe the feature / enhancement and how it helps to overcome the problem or limitation
I am proposing that functionality be added to GDScript that allows the user to specify that a property should only be drawn in the inspector if it is on the root node of the currently-edited scene. This will make it easier to adhere to the "black box" philosophy of scenes in Godot, and hide extraneous cluttering information from the user as they work with scenes on a higher level.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
For now, I propose adding an annotation to GDScript,
@export_if_root
, which is added in addition to an existing@export
annotation (or one of its many variants). When this annotation is added to a property, the property is only considered to be drawn if it is the root node of the scene currently being edited.GDScript code of the current implementation:
This is currently implemented in my branch of Godot here: https://github.com/Meorge/godot/tree/export_if_root
I recognize that this is not necessarily the best exact syntax for this feature, and should be discussed before anything is merged. Here are a few alternatives I thought of.
@export @if_root var my_property
- This reads a bit more naturally and takes up less space. However it may be confusing to see on its own, and/or incorrectly imply that it modifies the behavior of other decorators as well.@export(true) var my_property
- Making this annotation into an argument for@export
would certainly be the most succinct approach, but it would have to be added onto every variant of@export
. On top of that, the lack of keyword arguments means that it's not immediately clear what the argument refers to. One could reasonably - yet incorrectly - assume that@export(true)
means "export this variable" and@export(false)
means "don't export this variable".If this enhancement will not be used often, can it be worked around with a few lines of script?
As users take further advantage of nested scenes, this enhancement will be used more and more.
The behavior can be accomplished with pure GDScript, but it feels rather clunky to me when combined with regular game code:
This has a few drawbacks, in my opinion:
@tool
annotation to the script, making it run in the editor, we have to add checks in (at least) the_ready()
and_process()
functions to ensure that the actual script behavior only runs when the game is playing. This boilerplate feels unnecessary and bloated to me._validate_property()
function isn't immediately intuitive or readable in my opinion. Additionally, requiring the property names to be written in an array means that if for some reason the user changes the property names, they'll have to go back and change them here as well. With an annotation on the variable itself, this wouldn't happen.Is there a reason why this should be core and not an add-on in the asset library?
I don't believe there is a way to create custom annotations or modify existing ones with how Godot and GDScript currently works. Thus, I think it would have to be core rather than an add-on.
The text was updated successfully, but these errors were encountered: