-
-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Automatically duplicate a dictionary #38792
Comments
This is not a bug, but a design decision (passing by reference helps decrease memory usage). The same also applies to Arrays. As far as I know, there are no plans to change this for Godot 4.0. Note that PoolArrays are passed by value (instead of reference), though. (They were renamed to PackedArrays in the
This is already mentioned in the Array class description, but not yet in the Dictionary class description. I'll add it ASAP. |
To be fair, it is explicitly stated in the GDScript basics doc. |
See godotengine#38792. (cherry picked from commit 675fea1)
See godotengine#38792. (cherry picked from commit 675fea1)
Godot version:
3.2.1
Issue description:
You need to use the .duplicate(true) function in order to copy the dictionary instead of referencing to it.
With every other value type, it is done automatically (it copies the value instead of referencing the variable itself).
Now, if I want to copy part of the dictionary and make changes to it, the BOTH dictionaries are changed. This has caused me a lot of confusion because I keep forgetting that this one type of value for some reason behaves differently then all the others.
Steps to reproduce:
Create two dictionaries --> assign one to the other --> change one of them --> see the other one change as well.
If you repeat those steps with any other type of value (string, integers, etc.) you won't see this behavior.
Minimal reproduction project:
dict.zip
I know this behavior might be intended but it's not clearly stated anywhere that there is a variable exception such as this. The first time it happened, I discovered this behavior by accident after many, many hours of confusion.
The text was updated successfully, but these errors were encountered: