-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Adding @export_if(condition) to streamline conditioned properties exposing in inspector #9842
Comments
Note that annotation arguments must be constant expressions. Annotations are resolved at compile time and are the same for all instances of the class. So the condition cannot be arbitrary and cannot be written as you would expect. Only something like Also, you can use Related: |
I standby that there should be an easierl way to do this but _validate_property() is nicer indeed and will do for me for now, thanks |
I REALLY don't see the reason why this shouldn't be added, it is like saying "why would you need a Sprite2D node when you can use draw_texture()?" Having to use a @tool script + parsing the variable name manually (and changing it accordingly when refactoring) is so much more complicated than adding an annotation. |
I'm also of the opinion that this is a very reasonable addition, and would considerably improve quick prototyping. I rely a lot on scripts like these, that have a lot of different behaviours built in that are toggled in the inspector, and the lack of a quick solution is pretty grating. |
Describe the project you are working on
A RPG where entity has states that determines if some properties are required or not.
Describe the problem or limitation you are having in your project
I have a shop script, where the seller can either have one price for everything, or everything has its own price and currency.
I wrote a bool
use_unified_cost
, and I have 2 sets of @export variables to account for each kind of seller; Considering only one property set would be useful for a time, I want the editor to only show some of them depending on the state ofuse_unified_cost
.(You can ignore all these and just think about
motion_mode
inCharacterBody2D
, the engine itself already showcased the use case.)notify_property_list_changed()
and_get_property_list()
method inObject
documentation works, but it's requiring a lot of detail information about how to represent the property in the editor. I'm still stuck on it fillingnull
into my customTradeOptionCost
resource array, which would work if I simply use@export
.It's also currently only adding the properties to the button of the export list, which I believe is solvable, but...I just don't see why it should require these low level knowledge for the function.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add a
@export_if(condition)
annotation, which only expose itself in inspector ifcondition
is true.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Use the example from the official doc:
(
@tool
andnotify_property_list_changed()
might still be required, but not using_get_property_list()
saves many lines and effort.)The condition can also be (A and B) or (state == State.A), so there will probably be very complex use case.
If this enhancement will not be used often, can it be worked around with a few lines of script?
Somewhat, it would at least require calling a function and construct something and return, and one property would be appending a new dictionary.
My current code look like this:
Would be 4 lines if it's implemented.
Is there a reason why this should be core and not an add-on in the asset library?
It's a core part of the GDScript.
The text was updated successfully, but these errors were encountered: