Jul-09-2022, 04:28 AM
(This post was last modified: Jul-09-2022, 11:59 AM by deanhystad.)
Assignment of mutable objects should always set off warning bells. This does not create a copy, it assigns two variables to reference the same vector.
Using assignment with non-mutable values is fine. Being non-mutable means the underlying value cannot be changed elsewhere without your knowledge. However, when you are working with lists or dictionaries, make sure that "=" is doing what you want. If you really just want a local variable that references the same object as another variable, fine, use assignment, but if you want your own unique copy, a copy has to be made.
self.vector = vectorAnd as you now know, you ended up with all your particles referencing the same vector object.
Using assignment with non-mutable values is fine. Being non-mutable means the underlying value cannot be changed elsewhere without your knowledge. However, when you are working with lists or dictionaries, make sure that "=" is doing what you want. If you really just want a local variable that references the same object as another variable, fine, use assignment, but if you want your own unique copy, a copy has to be made.