Dumb question: How to set all 3 components of Vector3?

I’m looking for something like: vec.set( 1, 0, 0 ); as opposed to vec.x = 1; vec.y = 0; vec.z = 0; That is all :slight_smile:

1 Like

It is not a dumb question - there are complexities of value type vs reference type invovled. I think that the easiest way is to simply create a brand new Vector by

vec = new Vector3(X, Y, Z);

This is probably the best method anyways because the Vector3 is not a class (reference type), but a struct (value type). This means that unlike most objects you work with, the vec is simply the Vector3, not a pointer to where the Vector3 exists in memory. See the linked articles above for the internal workings.

Because this is a struct and not a class, I believe the most reliable way to change all three values at once is to simply create a brand new Vector, because the program is going to do that anyways.