Open EviTRea opened 2 months ago
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 @export_if("holding_hammer")
.
Also, you can use _validate_property()
with @tool
.
Related:
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
@export_if("holding_hammer")
.Also, you can use
_validate_property()
with@tool
.Related:
* [Ability to dynamically hide exported variables in the inspector #1056](https://github.com/godotengine/godot-proposals/issues/1056) * [Allow conditional exports (or sub-exports) #2582](https://github.com/godotengine/godot-proposals/issues/2582) * [Add `@export_toggle` to GDScript #8717](https://github.com/godotengine/godot-proposals/issues/8717)
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 Not sure if I should close this though, doesn't seem to be duplicate, guess I'll just leave it here
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 aboutmotion_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.