-
-
Notifications
You must be signed in to change notification settings - Fork 99
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 @required
annotation for exported properties
#8343
Comments
@required
annotation for exported fields@required
annotation for exported properties
I would prefer something like #1729, which is a more universal solution and doesn't error if the variable isn't used anywhere. |
This would not solve the issue with And still the issue would only arrive when the game is already running. What I want is to have a built-in problem reporting for exported properties the same way it's done for physics objects missing collision nodes |
You could use configuration warnings combined with godotengine/godot#68420 |
Yes, this is what I am currently doing, but it requires me make my scripts I think it's an overkill to do all those check by hand for a simple is-null validation. 68420 is great for heavy cases, where you do more than that |
var cam1 = get("sub/camera")
var cam2 = $sub/camera So it would be nice to have the proposed feature. I would guess that getting new features to export variables would be more possible than automatically renaming node paths. Currently I'm doing something like this: @export var camera: Camera2D
func _ready():
assert(camera) The feature could also be something like automatically asserting on |
Similar to #2519 Right now, the intended way to customize inspector properties is to either: It's not very ergonomic to implement reusable property editors at the moment. Give users the power to make custom annotations that change how exported properties are rendered in the inspector, then provide a few built-in validation annotations like This doesn't necessarily have to be implemented via annotations, but there should be some way of declaratively composing inspectors rather than messing with |
What about a slightly more general approach where you can tag properties as described in this proposal: #8752 Instead of writing @required
@export var node : Node you could write @tool
@tag("required")
@export var node : Node :
set(value : Node) :
node = value
update_configuration_warnings()
func _get_configuration_warnings() -> PackedStringArray:
var warnings : PackedStringArray = []
var properties : Array[Dictionary] = get_tagged_properties("required")
for property in properties:
if get(property.name) == null:
warnings.append(property.name + " is required") |
Because then you have to reimplement this feature in every script you create. |
I would also like to see this in some form, but I think this could be implicit whenever #162 is implemented. I understand that nullable types would be a breaking change, so I hope they go the same rout as they did with static typing and make it an opt in setting. |
Describe the project you are working on
3D adventure
Describe the problem or limitation you are having in your project
I am heavily using
@export var node: Node
whereNode
is anyNode
descendant to avoid depending much on node paths, but sometimes s.. happens and I simply forget to set a value to the field in the inspector, and in such cases I will only know about that in runtime.Describe the feature / enhancement and how it helps to overcome the problem or limitation
It would be great to have something like an annotation (e.g.
@required
or@export_required
)Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
When a property is marked as required the inspector would promt you about it the same way configuration warnings do, but also highlight the missing property (e.g. the yellow triangle may be placed in front of property saying it's required to be set to a value).
This would not only work for nodes, but also for any
Object
descendant, likeResource
.If this enhancement will not be used often, can it be worked around with a few lines of script?
A possible workaround would be to mark scripts with
@tool
and check for the properties in_get_configuration_warnings
Is there a reason why this should be core and not an add-on in the asset library?
It requires changes to gdscript
The text was updated successfully, but these errors were encountered: