ResourceSaver removing bool data types when default value is set to it

Godot Version

4.7.stable

Question

I use a resource (SaveData.res) to serialize some values in my game. Everything is saved properly when I inspect the res file except for booleans. When the var gets the default value, the line (var name and value) are erased from the resource file. I've seen Godot do some optimizations when value does not change but in this case, the line is completely removed from my resource file. For instance, the var starts to false and is written in the resource but when I turn it to true and save, the line disappear from the file.

Is there a problem there?
A default value is implicit so it doesn’t have to be explicitly saved. It’s redundant. If the loader doesn’t find the value override in the resource file - it will just use the default value. So you’ll always get the correct value back.

I get your point but I’m balancing clarity / explicit vs performance here. I would like to have the choice to keep this line in my resource file no matter if it has the default value or not.

I’ve worked around by using an int but I’d hope there is another way so if you know any.

Why?

Wouldn’t int behave in exactly the same way?

When I debug, I do prefer see the line being written with its value. If the line is not there, it’s harder to konw whether the writing file is the issue or if it’s because it has the default value and had been optimized.

Also, when looking at the file, it’s hard to remember every field that should be there, so if the file is empty because everything is at its default value I would have to read a blank file.

Again, I’m not sure the optimization it brings worth the lack of clarity but maybe I’m wrong.

Saving hundreds of values for a single type is not clarity, quite the opposite

In my case, it’s around 10 values, this is why I propose this could be an option to not optimize it.

It can still be the default behaviour though.

Why do you need to look directly at resource files when debugging?

To check whether values have been properly saved or not.

Is there a way to avoid the optimization, I mean, built-in option to have the value written no matter what ?

besides, isn’t it a problem to optimize the file ?

imagine you test your game and everything looks fine but once in the wild, some players have found a way to change all the values, thus no optimization can be made… in this case, I would rather have noticed it before. no ?

How do you mean? How would this be a problem?

How can a value be “improperly” saved? You can always reload back and check.

I don’t get it. If someone wants to mess with values in resource files, how is saving defaults in there preventing this?

This looks like an XYproblem.

just asking, is there a built-in way or is forced optimized ?

I don’t know, try using _property_get_revert, or check in the documentation

Are your properties annotated as @export?

yep, the serialization works nicely except this disappearing value has drove me nut until I found the optimization explanation in the doc.

thanks for help guys