You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Variables that define a setter don't use it on init:
varclamped=5:
set(value):
clamped=clamp(value, 0, 1)
func_ready() ->void:
print(clamped) # prints '5'clamped=clamped# "solved" by doing this very clever trick for each variableprint(clamped) # prints '1'
This makes for an inconsistent behavior when using exported variables since the setter is triggered when setting the export value:
@exportvarx:=4:
set(value):
x=valueprint("This only prints for modified export values.")
Steps to reproduce
see snippets above
Minimal reproduction project
No response
The text was updated successfully, but these errors were encountered:
This is intended, see #36496
When you export a variable and change it, it will be set during scene load, which will trigger the setter. It doesn't happen for default values, because they are initialized directly in the constructor (this is consistent with what happens internally in C++).
Maybe we could document it better, if it isn't already.
Calinou
changed the title
GDScript 2.0: variables don't use their setters on initialisation
Exported variables don't use their setters on initialisation
Oct 10, 2023
This is intended, see #36496 When you export a variable and change it, it will be set during scene load, which will trigger the setter. It doesn't happen for default values, because they are initialized directly in the constructor (this is consistent with what happens internally in C++).
Maybe we could document it better, if it isn't already.
I think this is a case where the programmatic intended behavior is at odds with an intuitive user experience from a designer perspective. There seems to be a legitimate programmatic case to be made for this behavior, but for a user with limited understanding of how Godot works internally, this feels like an inconsistency and a surprising behavior that is difficult to diagnose.
Godot version
4.0.alpha11, but the behavior is the same in 3.x
System information
Linux
Issue description
Variables that define a setter don't use it on init:
This makes for an inconsistent behavior when using exported variables since the setter is triggered when setting the export value:
Steps to reproduce
see snippets above
Minimal reproduction project
No response
The text was updated successfully, but these errors were encountered: