Dictionary and array updating

TLDW : if I iterate over an array that stores a dictionary and I → return the dictionary to another function and make an update, will it update the item in the array?

Yes it does… man godot is awesome. I’m sure I had to do heaps more to make this work in unreal since you couldn’t update dictionaries in array etc.

1 Like

For some more detail here, base types are copied, strings are a little special, and everything else is referenced. Base types being int, float, and bool. Everything else will have a .duplicate() function to explicitly create a copy, otherwise it’s a reference.

Copies are as they sound, a new version of the last item stored in different memory.

var a = 10
var b = a

b = 20

print("a: %d, b: %d" % [a, b]) # a: 10, b: 20

Refernces are the same memory location under different names. This is particularly useful for functions to modify inputs or returns like you have found.

var a = [10]
var b = a

b[0] = 20

print("a: %d, b: %d" % [a[0], b[0]]) # a: 20, b: 20

String are special in Godot because they use a copy-on-write system that makes them behave like a copy, but still saves memory like a reference (when not modified).