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
In GDScript, when exporting a variable of an enum type that does NOT have an entry with value 0 (zero), and you don't a default value, the inspector looks as if you have selected the first element, but in truth, the value of the variable is 0.
Given the following snippet:
enum Foo{
bar = 1,
foobar = 2,
}
@export var foo : Foo
The inspector looks like this:
This suggests bar is selected, and thus foo should be 1.
However,
func _ready():
print(str(foo))
prints 0 (zero).
If you do give a default:
@export var foo : Foo = Foo.bar
the inspector looks exactly the same as it did without the default specified, but the output is the (expected) 1. As a user, I thus can't tell the difference without inspecting the code.
As a user, I expect that whatever is shown in the inspector is a representation of what I'll get when I run the code. So when no default is specified, I expect that either (the inspector shows 0 or null) or (the value of foo ends up being bar instead of 0). Ideally, I would like it to do the latter, but I think that the former is technically more correct
Steps to reproduce
Make a new scene
Attach the following script:
extends Node
enum Foo{
bar = 1,
foobar = 2,
}
@export var foo : Foo
func _ready():
print(str(foo))
Observe that the inspector for this node suggest that foo is set to bar.
Run the code, and observe the ouput prints 0 instead.
Change the export line to @export var foo : Foo = Foo.bar
Observe that the outliner looks exactly the same as before
Run the code, and observe that the output now reads 1.
Minimal reproduction project
n/a, but can be supplied if helpful.
The text was updated successfully, but these errors were encountered:
Ulugbeg
changed the title
GDScript: Exported vars of enum types without value 0 show misleading info in inspector
GDScript: Exported vars of enum types which have no default set, and with no entry with value of 0, show misleading info in inspector
Feb 28, 2023
Ulugbeg
changed the title
GDScript: Exported vars of enum types which have no default set, and with no entry with value of 0, show misleading info in inspector
GDScript: Exported vars without a default set, of enum types with no entry with a value of 0, show misleading info in inspector
Feb 28, 2023
akien-mga
changed the title
GDScript: Exported vars without a default set, of enum types with no entry with a value of 0, show misleading info in inspector
Exported vars without a default set, of enum types with no entry with a value of 0, show misleading info in inspector
May 11, 2023
See also #75555. The inspector should take into account that the property may have the wrong type or value and display it. For example, if the number is out of range, the text should be red and/or an exclamation mark icon should be displayed. In the case of enums, OptionButton has support for the unselected state.
A small warning to use a default value with enums will be helpful if it's hard to change the editor's behavior. I lost a few hair patches figuring this out!
I opened #90756 to show a warning if the default value isn't set (when 0 isn't a valid value). Ideally, the default would be the first value of the enum, but that's a bit difficult to figure out.
Still, the inspector should show the actual value and perhaps warn when it's not part of the enum.
Godot version
v4.0.rc6.official [0cd1483]
System information
Arch Linux
Issue description
In GDScript, when exporting a variable of an enum type that does NOT have an entry with value
0
(zero), and you don't a default value, the inspector looks as if you have selected the first element, but in truth, the value of the variable is0
.Given the following snippet:
The inspector looks like this:
This suggests
bar
is selected, and thusfoo
should be1
.However,
prints
0
(zero).If you do give a default:
the inspector looks exactly the same as it did without the default specified, but the output is the (expected)
1
. As a user, I thus can't tell the difference without inspecting the code.As a user, I expect that whatever is shown in the inspector is a representation of what I'll get when I run the code. So when no default is specified, I expect that either (the inspector shows
0
ornull
) or (the value offoo
ends up beingbar
instead of0
). Ideally, I would like it to do the latter, but I think that the former is technically more correctSteps to reproduce
foo
is set tobar
.0
instead.@export var foo : Foo = Foo.bar
1
.Minimal reproduction project
n/a, but can be supplied if helpful.
The text was updated successfully, but these errors were encountered: