Vector3 method copyFrom(), returns Vector3 with undefined values, when copies from object

I bumped into this issue when updated Babylon from version 4.1.0 to 4.2.0.

It looks like you can pass an object to copyFrom(source: DeepImmutable<Vector3>): Vector3; method as DeepImmutable extends DeepImmutableObject, so I assume it should be able to parse an object.

Plus, in my opinion, changing something like that would result in backward compatibility issues, which makes me think that maybe it’s the bug indeed.

Here is example in playground:

It works in v 4.1.0, but if you change to v 4.2.0 all Vector3 values are undefined.

The issue is that you are not copying from a Vector3 object here, and this was working by luck before.

The only thing you can copy from would be another vector, if it is not the case you could use the copyFromFloats method to ensure it stays back compatible.

1 Like

Thanks for the quick response.

Yeah I assume they changed x, y, z to _x, _y, _z in Vector3 constructor function and that’s why it stopped working (i might be wrong tho)

`Vector3.prototype.copyFrom = function (source) {
    return this.copyFromFloats(source._x, source._y, source._z);
};`

But you are right, it’s better to use object of correct type in order to avoid such surprises.

1 Like