godot: Exported enum - inspector selection breaks when enum is updated to contain additional values

Godot version

3.4.stable

System information

Windows 7 64 bit

Issue description

Creating enums with auto-assigned integer values ends up as a bad experience when exporting them for editing in the inspector, and you need to later update them. I could have 100s of instances of an object I made but I need to add a new enum value, and this ends up breaking all of my object instances because the actual assigned values of the enums changed.

If I’m using this syntax, that means I don’t want to be concerned with the actual value of the enum, I only care that the enum name matches before the interpreter comes in to replace with an integer value.

enum SOME_ENUM {
    APPLE,
    PEAR,
    PEACH
}

But since the inspector seems to care about the integer value, not the enum name, you can end up with a mismatch of state if you add new values to the enum.

Steps to reproduce

enum SOME_ENUM {
    APPLE,
    PEAR,
    PEACH
}

export(SOME_ENUM) var enum_selection

In the inspector, select PEACH for “Enum Selection”.

Update SOME_ENUM to contain a value that comes before PEACH, such as:

enum SOME_ENUM {
    APPLE,
    GRAPE,
    PEAR,
    PEACH
}

Now “Enum Selection” will say “PEAR” instead of “PEACH”.

I’m assuming this is because Godot stores the integer value for the enum, since the integer values are auto assigned in this case, the values increment.

Minimal reproduction project

No response

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 2
  • Comments: 27 (26 by maintainers)

Most upvoted comments

Maybe a different approach,

If you were forced to put the warning here next to the dropdown only when an enum that has unassigned values is used, and make whatever change to the codebase is necessary, otherwise you’ll die, how would you do it?

image

it is completely fine to use enums without specific numeric values

If the editor worked like your typical user will assume it did and remembered the enum selection based on its name, it would be perfectly fine. But adding new values to an enum happens all the time, like way more often than I think you’re anticipating, during the course of game development. This definitely deserves a warning for this very specific scenario with inspector exports if it isn’t outright fixed to somehow remember based on the enum name.

Inspector doesn’t “store” anything. It’s merely a UI to display and allow you to edit exported properties of your classes. And enum is an integer, it is stored as an integer.

You assume correctly, enums are not a type of data in GDScript, it’s just a list of constants (if unnamed), or a dictionary (if named). It behaves as expected.