Signal parameter seems to stay variable after sending

Godot Version

4.6.2 stable

Question

So, in my Project, i have two sepereate scenes. one of them is a UI that lets you configure certain keys in a dictionary. Once you click a “save” button in said scene, it emits a signal with that dictionary as a parameter.

The other scene has a function connected to this signal, and said parameter will be packed into another dictionary in that function.

Now, the problem is that this parameter that gets passed to scene 2 seems to stay variable after being put into the dictionary, because when I repeat that process of editing and saving the smaller dictionary in scene 1, all the dictionaries that were sent from scene 1 to 2 seperately will have the keys and values of the dictionary that was sent last.

This is the code of the function in scene 2:

func save_pattern(pattern):
inputs.append({“cube”: pattern})

I hope my explanation is somewhat coherent and makes sense, im very confused.

Thank you so much for your help!

In GDScript, arrays and dictionaries are always passed by reference. When passing a dictionary as argument to a function, you don’t get a duplicate of the dictionary, but a reference to that same dictionary.

You can call .duplicate() on a dictionary to get a copy.