Exported enums should remember set key, not values. #9128
Replies: 2 comments 1 reply
-
This is a core issue, built-in enums also store values, not keys (so we try not to shift values). This could be solved with a new usage flag and annotation, but if I remember correctly, the built-in enums do not store keys in release builds to save space. As a workaround, you can explicitly specify the enum values: enum Foo {
A = 0,
B = 1,
C = 2,
# Add new values to the end, don't shift IDs!
}
@export var boo: Foo = Foo.A or use the @export_enum("A", "B", "C") var boo: String = "A" |
Beta Was this translation helpful? Give feedback.
-
If you remember the keys instead of the values, the problem is not solved, but it is shifted to the keys. If you change the name of any key the same issue happens. The editor should also not be trusted in predicting what has been changed and how. This is the kind of thing that some sort of refactoring tool could help manage (something that has been asked many times before). |
Beta Was this translation helpful? Give feedback.
-
If you change order of enum keys in script, all exported variables of this enum are going to be shifted.
E.g. in the following example if I set
boo
toC
via editor and then change order or insert element inFoo
,boo
key will change.enum Foo {A, B, C}
@export var boo: Foo = Foo.A
I would like to propose that in such cases exported variable is assigned a value corresponding to key set in editor.
Beta Was this translation helpful? Give feedback.
All reactions