Skip to content
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

Exported vars without a default set, of enum types with no entry with a value of 0, show misleading info in inspector #74123

Open
Ulugbeg opened this issue Feb 28, 2023 · 4 comments

Comments

@Ulugbeg
Copy link

Ulugbeg commented Feb 28, 2023

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 is 0.

Given the following snippet:

enum Foo{
	bar = 1,
	foobar = 2,
}
@export var foo : Foo

The inspector looks like this:

image

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

  1. Make a new scene
  2. Attach the following script:
extends Node

enum Foo{
	bar = 1,
	foobar = 2,
}

@export var foo : Foo

func _ready():
	print(str(foo))
  1. Observe that the inspector for this node suggest that foo is set to bar.
  2. Run the code, and observe the ouput prints 0 instead.
  3. Change the export line to @export var foo : Foo = Foo.bar
  4. Observe that the outliner looks exactly the same as before
  5. Run the code, and observe that the output now reads 1.

Minimal reproduction project

n/a, but can be supplied if helpful.

@Ulugbeg 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 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 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
@akien-mga
Copy link
Member

Also valid with C# exported variables as seen in #76933.

@dalexeev
Copy link
Member

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.

@goranovs
Copy link

goranovs commented Apr 12, 2024

This is still the case in 4.2.1.

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!

@vnen
Copy link
Member

vnen commented Apr 16, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants