-
-
Notifications
You must be signed in to change notification settings - Fork 21.9k
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
ResourceSaver duplicates items in all arrays #29179
Comments
The actual problem here is that each exported array is the same instance. I remember it being mentioned/reported somewhere (like this related issue #20436), but not sure if there was some proper fix/workaround. btw, this makes Resources almost useless for saving game progress, because you often need to use arrays in complex games. |
The erroneous sharing between typed arrays and dictionaries should be fixed in 3.2, see #24134
|
Hey, thanks for the heads up @PetePete1984 I ended up using class Save:
extends Resource
export var version : String = "1.0"
export var save_name : String = "Whatever"
export var save_data = {
"nodes": [],
"connections": []
} |
Stumbled upon the same issue. Can confirm, @PetePete1984's workaround suggestion works. |
So, another way to avoid this is not initializing the arrays:
They are initialized automatically to unique references. |
The issues related to this mentioned that dictionaries also had this problem; in my own experiments, the dictionaries were fine, but the arrays would still share the same instance. Not initializing them does the trick. |
Eh, if someone is interested, godot/modules/gdscript/gdscript_parser.cpp Line 927 in 4ee8ecd
godot/modules/gdscript/gdscript_parser.cpp Line 1619 in 4ee8ecd
Same operation for dictionaries uses exactly the same code, so not sure where is the part that makes arrays shared (but probably there are some parts I'm not aware of and these might differ. Dunno). I used #28603 to get a clue where to look, but then got stuck :/ |
Still valid in a609b30 I'm surprised that GDScript 2.0 still has this problem. |
Would it be because arrays were made to be compared by value (even though they are ref types), therefore making them under the same key if indexed in a map or hashmap? If dictionaries also get compared by value they might end up with the same problem |
Except property name is the key in hashmap, not its value. |
Godot version:
3.1
OS/device including version:
Windows 10
Issue description:
ResourceSaver duplicates items in all arrays upon saving
Minimal reproduction script:
test.tres:
The text was updated successfully, but these errors were encountered: