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

**URL:** https://forum.babylonjs.com/t/vector3-method-copyfrom-returns-vector3-with-undefined-values-when-copies-from-object/16730
**Category:** Bugs
**Created:** [December 17, 2020, 10:05pm UTC](https://forum.babylonjs.com/t/vector3-method-copyfrom-returns-vector3-with-undefined-values-when-copies-from-object/16730 "2020-12-17T22:05:08Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![IT-REX](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/it-rex/32/50033_2.png) [@IT-REX](https://forum.babylonjs.com/u/IT-REX)
#### Post date: [December 17, 2020, 10:05pm UTC](https://forum.babylonjs.com/t/vector3-method-copyfrom-returns-vector3-with-undefined-values-when-copies-from-object/16730/1 "2020-12-17T22:05:08Z")

</div>

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:

> **[Babylon.js Playground](https://playground.babylonjs.com/#BIRLKU%231)**

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

---

<div class="post-metadata">

### Author: ![sebavan](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/sebavan/32/57_2.png) [@sebavan](https://forum.babylonjs.com/u/sebavan)
#### Post date: [December 17, 2020, 10:10pm UTC](https://forum.babylonjs.com/t/vector3-method-copyfrom-returns-vector3-with-undefined-values-when-copies-from-object/16730/2 "2020-12-17T22:10:24Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![IT-REX](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/it-rex/32/50033_2.png) [@IT-REX](https://forum.babylonjs.com/u/IT-REX)
#### Post date: [December 17, 2020, 10:28pm UTC](https://forum.babylonjs.com/t/vector3-method-copyfrom-returns-vector3-with-undefined-values-when-copies-from-object/16730/3 "2020-12-17T22:28:57Z")

</div>

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.
