-
-
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
Allow conditional exports (or sub-exports) #2582
Comments
This can be achieved with |
Here's an example project showcasing it: Test project: tool
extends Node2D
export(bool) var pickable = false setget set_pickable
var pick_level: int
func set_pickable(p_pickable):
pickable = p_pickable
property_list_changed_notify()
func _get_property_list() -> Array:
var list = []
if pickable:
list.push_back(
{ name = "pick_level", type = TYPE_INT }
)
return list
The Or would you rather suggest a GDScript-specific solution to this? It depends on how common this feature will be used in other projects to justify implementing it on the language level. In C++, this is also achieved with |
Maybe there could be a @export_conditionally(expression) annotation? So your example would be:
I feel it would be useful to hide properties that depend on other properties, to avoid confusing users with properties that don't affect anything. |
One issue with We should probably ensure exported-but-hidden properties are always saved by default to avoid data loss. |
Yes, data loss should be avoided when possible. Maybe some name with visibility instead? As it's not visible in the inspector, something like Regardless of the name I feel like it would be a very useful feature to have as it's quite a common usecase imo, and it would be nice to avoid having to override the property list for it. |
If the property is conditional and the conditional is not met, it means you don't need it and there is no data loss. Property value is chached internally until scene is reloaded, so accidental data loss is unlikely too. |
I wonder if this would be useful for the editor itself. Right now the Button's icon alignment property is shown for example regardless of a icon is selected or not. Showing properties that don't affect anything is defiently confusing for the user. |
We already use conditional properties in the editor. This proposal is about GDScript convenience, which wouldn't have any use in the editor. |
This is actually a duplicate of #1056. The OP there proposes a different solution, but an annotation is more likely to be accepted if we implement this (and also proposed in the comments). |
Describe the project you are working on
Text-based RPG
Describe the problem or limitation you are having in your project
I have a "door" class that exports a number of variables to the editor for easy configuration, relevant to this topic I have:
pickable: bool
pickLevel: int
pickLevel is useless if the door is not pickable, and only serves to clutter the script exports dock thing in the editor. For one variable this isn't a big deal, but if I were to add other things like kicking down doors or casting spells to unlock them, each depending on a different stat, it would quickly get out of hand.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
Allow exporting variables conditionally, or attaching exports to other exports, such that
pickLevel
is only exposed to the editor ifpickable
is True.Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
I don't know how to cleanly express this in code, but maybe something like this:
or maybe something with decorators?
or conditionals:
If this enhancement will not be used often, can it be worked around with a few lines of script?
As far as I'm aware there is no way to achieve this functionality currently.
Is there a reason why this should be core and not an add-on in the asset library?
It changes the core export system.
The text was updated successfully, but these errors were encountered: