Updating a Class containing a Resource. New dictionary data of Resource is ignored

Godot Version

4.3.stable

Question

I have a class named EnemyData extending Resource. It contains several vars. One of those is a dictionary named attributes. It looks like this:

Now, I realized I had forgotten to add Base_Speed months ago, so I just added it.

Now, my problem is, when I open the specific enemy classes to give them their proper value, the dictionary entry isn’t even there (shown below). Meaning, it hasn’t updated the content. I use that in the 12 enemy classes I use. Am I damned to have to manually add each key/value pair for each class? Or is there a way to do that and I’m just blind to it?

If you change the default value @exported in the dictionary it will keep the modified version. As this is a resource, would it be better to use @export var for each dictionary key/value?

That’s what’s throwing me off here. The values (and their keys) should remain as they are if they still exist in the Resource, but if the Resource has changed (added/removed keys) they should be updated accordingly.

I was wanting to avoid this specifically as I would only have to open the .tres file then edit the new key/value and be done. The added benefit was that it would greatly diminish typos, forgetting adding, etc.

Let’s say I disagree with the choice of making the Resource a mirroring of past state of the content of the Resource.

Edit:
PS: Even if I add a key manually to the TRES, it’s still error prone. throws hands in the air

The resource hasn’t changed, it’s dictionary has. The modified value doesn’t include the new key, but the export doesn’t care, it’s a modified dictionary it’s going to keep your changes.

The same procedure applies to @export variables, this is editabled from .tres files, and new variables are added without resetting the old ones.

class_name EnemyData extends Resource

@export var unit_name: String = "UNSET"
@export var strength: int = 10
@export var intellect: int = 10

My bad here. Wording is wrong. When I say Resource I mean the content of the attributes var (Dictionary) in the Resource.

Maybe I’m missing something obvious, but I can’t see why not keeping track of a dictionary that might have changed, key-wise, is the way to go.

If the content of a Dictionary, as @export’ed, does not have the same exact characteristics (keys), it should be updated to mirror that state.

Yes, but then you have to edit each and every instance where you use it if you decide to modify the “dictionary” (which isn’t a dictionary anymore, but you get what I mean). The way I’m doing it, if it worked the way I wanted it, would mean I edit the dictionary once, then open the .TRES file and put the right value in.

I prefer 1 edit to 12+.

Anyway, it is the way it is. I don’t like it, but here we are.

Thanks.

That’s not something the language would know about your game, what if I want different keys to my dictionary? Rarely do I use dictionaries with all the same keys.

Isn’t this why you have the .tres file? I don’t know your project structure but it seems like something is missing, as I see it for this use case, individual properties have no downsides where dictionaries have plenty.

I don’t see how this is different from adding a property once and editing the right value into the .tres.