Can I give array indices names in the editor?

Godot Version

4.6

Question

A very common format I find myself using is to create an enum alongside a packed array to index data out of the enum.
For instance, I have “Stats" for units in my game, where each value in the table stores
[ Range, Health, MaxHealth, etc… ]
This is very practical as it lets me make effects that hinder of buff an arbitrary stat by just swapping an enum.
For instance, I could have an attack that lowers a given stat from a unit by 3 with Stats[ENUM_VARIABLE] -= 3

The downside is that it makes the data very painful to set in the editor, as I just have to “remember” that enum value 5 is “Move Distance” and so on, leading to a lot of objects in my editor looking like this:


(making it very annoying to keep track of what value marks what data, especially whenever I add a new stat to the enum forcing the list to change size)

Does Godot have a way to display the names of each index as enum names instead of integers?
Or at the very least, is there a way to manually rename each element in an array so I can tag one as their respective stat name?

Probably better to extend a resource for StatCollection(s). I can’t imagine you’d want to iterate over different as an Array or dynamically add or remove stats, so it’s not necessarily a good fit as a data type

1 Like

You can use a dictionary instead of an array

1 Like

I don’t need to add or remove data, but iterating over them is actually pretty useful for displaying a list of stats in the UI.

But most importantly, keeping it a table that’s indexed with an enum allows me to create other scripts in the game that modify a variable stat.
If the StatCollection has a specific variable for “Health” or “Damage”, then I can’t easily make another script that modifies “Health” or “Damage” without making effectively two copies of the same script that just modifies a different variable.

yea but packed data is realllll nice
especially in my case as I have a lot of units and cells I want to manage at once- a dictionary feels like overkill if I’d just be using it to make the editor read a bit better

Not to mention, I kind of need the enum’s ability to be iterated over / compared to a specific integer. I’m using it for a glossary in my game used in my tooltip system, so indexing a dictionary with a string is a bit out of the question

“A lot” as in millions?

It may fell like it but it isn’t. Why would it be an “overkill”? A dictionary with an enum key is perfectly fine for this, although I’d just use a Resource class as @gertkeno already suggested.

My test room has an upper limit of 2,359,296 on a 1536x1536 grid :sweat_smile:
I probably never need to go this high, but I do enjoy optimizing how my project stores data.

I still really want the benefit of being able to index a specific stat using an enum, so I’m holding off on a resource as well.

I’m less asking for another approach, and more asking if there’s a way to just change the editor to show enum names next to the elements in the array instead of raw integers

You can make a plugin

1 Like

You can make a fake dictionary property using _get_property_list() just for inspector display and keep the internal storage in an array.

The only “clean” way is inspector plugin.

3 Likes

Cant you just have a second exported array with the strings on the corresponding indexes and update as needed, if the main array chsnges?

And then delete before exporting the game?

Just as a temporary visualisation.

But it sounds sketchy i m o.