Add an annotation which manually sets the default value for a get/set field on _ready #8460
MichaelMacha
started this conversation in
Editor
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
To elaborate, we can use get/set to perform special logic when a field is set in GDScript; but, it is never called for the default value unless done explicitly. If I have a scene with a number of child nodes which require configuration, and all of this configuration is in the set/get for
@export
-ed fields in the scene's root node, then I currently need to set the values of these nodes manually in_ready
to ensure that everything works as intended.As an example from my current project:
This works for a tumbling barrel that resets on a timer, but it feels way too close to a hack for me to be comfortable with the format of. Without the
_ready
instruction, it continues to be at its default time of three seconds.Here's what I would propose instead. Something like:
What @set_on_ready would do is run the
set(value)
instruction right before _ready, much as @onready does (but compatibly with @export). That would cause the $Timer node's fields to be updated, and keep my script substantially shorter and cleaner.Workarounds include the above, in some cases manually ensuring that the field always matches the default value (all kinds of issues there), and possibly tool scripts (which, again, potential issues). I don't really find any of these to be perfectly satisfying, so this feels like something the community and devs should weight in on before I go and propose it. Maybe I'm missing something?
The other option would be to perform this behavior by default, but I'm not sure what the runtime cost of that would be and whether it would be significant. GDScript is designed for usability, not performance, after all. My concern is that if this field caused, say, a map regeneration on the CPU side, it could add a lot of lag to scene load times. In such an instance, it might be even better to have an annotation like
@ignore_on_ready
which would prevent it from being set, if the set/get logic is too heavy.Beta Was this translation helpful? Give feedback.
All reactions