When trying to update the values contained within a PackedVector3Array, I was running into some weird behavior. I’m trying to update the vertex positions stored in an array before creating an array mesh.
This works:
for i in vertices.size():
vertices[i].y = randf() * 10.0
Vector3 isn’t RefCounted, kind of a base-type like int, or float. It is copied instead of referenced when assigned to a new variable, including a for loop. Within the loop you are editing the copied vector, versus using a created int to edit the array.
for vertex: Vector3 in vertices: # copies the Vector3
for i: int in vertices.size(): # creates an int
Ah that makes sense. I had been reading the notes scattered throughout the docs about this behavior for built-in types but wasn’t really sure how it applied, thank you