Is this a good practice to deep copy vector3 parameter in methods

I just now realized that vmath.vector3 passed by references. and because of that i had some bug. (sorry in unity vector3 is a struct and i didn’t thought about it =))

So is this ok to have something like

function func(position)
   position_param = vmath.vector3(position)
  ....
end

otherwise i can forget especially later when i’ll return to this code in couple of weeks where I don’t need to touch some values.

Yes, that would be very ok (if , as I understand, the intention is to create a new vector with the same values and avoid changing by reference).

Good to know is also that go.get_position and similar that returns a vector3|4 is NOT by reference so:
pos = go.get_position( gameobject1 )
pos.x = pos.x + 10
go.set_position( pos, gameobject2)

would not change position of gameobject1.

3 Likes