# The position value in the variable changes

**URL:** <https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343>\
**Category:** Bugs\
**Created:** [April 14, 2022, 7:22am UTC](https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343 "2022-04-14T07:22:22Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![qkrxotn7287](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qkrxotn7287/32/21866_2.png) [@qkrxotn7287](https://forum.babylonjs.com/u/qkrxotn7287)\
**Post date:** [April 14, 2022, 7:22am UTC](https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343/1 "2022-04-14T07:22:22Z")

</div>

This is Playground that reproduces the situation I experienced.

> **[Babylon.js Playground](https://playground.babylonjs.com/#YALRYC)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

The Position value of the Sphere that you put in the variable is updated in real time. Do you know why?

 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/0/d/0d9c10a2a150ac8df05d56fd9ab7ccd0a0b6d675.png)

My goal is to save the initial position of the sphere and change the position of the sphere to the initial value at the desired time.

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [April 14, 2022, 8:11am UTC](https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343/2 "2022-04-14T08:11:55Z")

</div>

when doing

```auto
spherePosition.push(sphere.position);

```

The reference to the position is pushed in the array, not the value itself. If you want to push the value, you need to do a copy.

```auto
spherePosition.push(sphere.position.clone());

```

---

<div class="post-metadata">

**Author:** ![Aze](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aze/32/23050_2.png) [@Aze](https://forum.babylonjs.com/u/Aze)\
**Post date:** [April 14, 2022, 8:13am UTC](https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343/3 "2022-04-14T08:13:37Z")

</div>

Push mesh.position is quate,you can clone it or new Vector3 then copyFrom(mesh.position).

---

<div class="post-metadata">

**Author:** ![qkrxotn7287](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qkrxotn7287/32/21866_2.png) [@qkrxotn7287](https://forum.babylonjs.com/u/qkrxotn7287)\
**Post date:** [April 14, 2022, 8:46am UTC](https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343/4 "2022-04-14T08:46:35Z")

</div>

> **[Babylon.js Playground](https://playground.babylonjs.com/#YALRYC%231)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

When the clone is applied, it is operated only once. The second is the same phenomenon as before…

---

<div class="post-metadata">

**Author:** ![Cedric](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/cedric/32/2742_2.png) [@Cedric](https://forum.babylonjs.com/u/Cedric)\
**Post date:** [April 14, 2022, 8:49am UTC](https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343/5 "2022-04-14T08:49:45Z")

</div>

it’s the same issue. you set a reference, not a value.  
change line 51 to be:

```auto
sphere.position = spherePosition[0].clone();

```

---

<div class="post-metadata">

**Author:** ![qkrxotn7287](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qkrxotn7287/32/21866_2.png) [@qkrxotn7287](https://forum.babylonjs.com/u/qkrxotn7287)\
**Post date:** [April 14, 2022, 8:55am UTC](https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343/6 "2022-04-14T08:55:53Z")

</div>

Wow! Thank you so muchHahaha  
Can you tell me why?

> **[Babylon.js Playground](https://playground.babylonjs.com/#YALRYC%233)**
>
> Babylon.js playground is a live editor for Babylon.js WebGL 3D scenes

---

<div class="post-metadata">

**Author:** ![qkrxotn7287](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qkrxotn7287/32/21866_2.png) [@qkrxotn7287](https://forum.babylonjs.com/u/qkrxotn7287)\
**Post date:** [April 14, 2022, 8:56am UTC](https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343/7 "2022-04-14T08:56:22Z")

</div>

I did an experiment! But I found a solution! Thank you for your answer.Haha

---

<div class="post-metadata">

**Author:** ![Aze](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aze/32/23050_2.png) [@Aze](https://forum.babylonjs.com/u/Aze)\
**Post date:** [April 14, 2022, 8:59am UTC](https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343/8 "2022-04-14T08:59:33Z")

</div>

Because the position is object and then every change of the object will take effect.So the mesh position will change.

---

<div class="post-metadata">

**Author:** ![Aze](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/aze/32/23050_2.png) [@Aze](https://forum.babylonjs.com/u/Aze)\
**Post date:** [April 14, 2022, 9:04am UTC](https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343/9 "2022-04-14T09:04:39Z")

</div>

Like this:  
var obj = {  
a: 1  
};  
var obj1 = obj;  
obj.a = 2;  
console.log(obj1.a) // console 2  
 ![image](https://us1.discourse-cdn.com/flex024/uploads/babylonjs/original/3X/8/c/8cd7cf0dc4c0b6d0cfc503f58d6749bdb4418c25.png)

---

<div class="post-metadata">

**Author:** ![qkrxotn7287](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/qkrxotn7287/32/21866_2.png) [@qkrxotn7287](https://forum.babylonjs.com/u/qkrxotn7287)\
**Post date:** [April 15, 2022, 1:21am UTC](https://forum.babylonjs.com/t/the-position-value-in-the-variable-changes/29343/10 "2022-04-15T01:21:52Z")

</div>

Aha! I seeHaha  
Thank you for your help!! 😀 😀
