# Issue with Resetting Mesh Position When Using new Vector3 in Array

**URL:** <https://forum.babylonjs.com/t/issue-with-resetting-mesh-position-when-using-new-vector3-in-array/60144>\
**Category:** Questions\
**Tags:** vector3, position\
**Created:** [August 19, 2025, 1:16pm UTC](https://forum.babylonjs.com/t/issue-with-resetting-mesh-position-when-using-new-vector3-in-array/60144 "2025-08-19T13:16:10Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![mmhosein.hp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mmhosein.hp/32/46314_2.png) [@mmhosein.hp](https://forum.babylonjs.com/u/mmhosein.hp)\
**Post date:** [August 19, 2025, 1:16pm UTC](https://forum.babylonjs.com/t/issue-with-resetting-mesh-position-when-using-new-vector3-in-array/60144/1 "2025-08-19T13:16:10Z")

</div>

Hi everyone,

I’m working on a Babylon.js scene with physics-enabled meshes. I want to reset the position of a mesh when I press the **R** key.

I noticed something strange:

- When I store `new BABYLON.Vector3` objects **directly in an array** , pressing **R** only works the first time.

- But when I assign the vector to a variable first and then use that variable in the array, it works correctly every time.

Here’s a playground link demonstrating the issue: [https://playground.babylonjs.com/#FSMQBW#55](https://playground.babylonjs.com/#FSMQBW#55)

Why does this happen, and how can I make the reset work reliably even when using `new Vector3` in an array?

Thanks in advance!

---

<div class="post-metadata">

**Author:** ![Heaust-ops](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/heaust-ops/32/45470_2.png) [@Heaust-ops](https://forum.babylonjs.com/u/Heaust-ops)\
**Post date:** [August 19, 2025, 1:22pm UTC](https://forum.babylonjs.com/t/issue-with-resetting-mesh-position-when-using-new-vector3-in-array/60144/2 "2025-08-19T13:22:10Z")

</div>

because you’re modifying that same `arr[1]` vector after you assign it to `mesh.position`, because the array and the mesh both hold onto the same object reference.

you can clone the Vector before assigning to avoid this.

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

---

<div class="post-metadata">

**Author:** ![mmhosein.hp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mmhosein.hp/32/46314_2.png) [@mmhosein.hp](https://forum.babylonjs.com/u/mmhosein.hp)\
**Post date:** [August 19, 2025, 1:33pm UTC](https://forum.babylonjs.com/t/issue-with-resetting-mesh-position-when-using-new-vector3-in-array/60144/3 "2025-08-19T13:33:42Z")

</div>

Thanks for the explanation! I tried using `.clone()` as you suggested. It works fine in the Playground, but in my actual code it still doesn’t fully reset the meshes.

```javascript
let playerPosL = [
    new Vector3(15, 0, 0),
    new Vector3(3, 0, 1.5),
    new Vector3(3, 0, -1.5),
    new Vector3(9, 0, -4),
    new Vector3(9, 0, 4),
   ]

function resetAllPos() {

    playerLeft.forEach((pl, i) => {
       if (pl && pl?.physicsBody) {
           pl.physicsBody.setAngularVelocity(Vector3.Zero());
           pl.physicsBody.setLinearVelocity(Vector3.Zero());
           pl.physicsBody.setMotionType(PhysicsMotionType.STATIC);
           pl.physicsBody.disablePreStep = false;
           pl.position = playerPosL[i].clone()
}
}

)}

```

---

<div class="post-metadata">

**Author:** ![Heaust-ops](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/heaust-ops/32/45470_2.png) [@Heaust-ops](https://forum.babylonjs.com/u/Heaust-ops)\
**Post date:** [August 19, 2025, 1:39pm UTC](https://forum.babylonjs.com/t/issue-with-resetting-mesh-position-when-using-new-vector3-in-array/60144/4 "2025-08-19T13:39:41Z")

</div>

I don’t see anything wrong w/ just that, can you repro that in a PG?

---

<div class="post-metadata">

**Author:** ![mmhosein.hp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mmhosein.hp/32/46314_2.png) [@mmhosein.hp](https://forum.babylonjs.com/u/mmhosein.hp)\
**Post date:** [August 19, 2025, 1:43pm UTC](https://forum.babylonjs.com/t/issue-with-resetting-mesh-position-when-using-new-vector3-in-array/60144/5 "2025-08-19T13:43:42Z")

</div>

Ah, I see! The issue was that earlier in my code I was setting the position like this:

```javascript
p.position = playerPosL[(i % playerPosR.length)]

```

Changing it to use `.clone()` fixed the problem:

```javascript
p.position = playerPosL[(i % playerPosR.length)].clone()

```

So the mesh wasn’t fully resetting because it was still referencing the same `Vector3` object.

---

<div class="post-metadata">

**Author:** ![mmhosein.hp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mmhosein.hp/32/46314_2.png) [@mmhosein.hp](https://forum.babylonjs.com/u/mmhosein.hp)\
**Post date:** [August 19, 2025, 1:47pm UTC](https://forum.babylonjs.com/t/issue-with-resetting-mesh-position-when-using-new-vector3-in-array/60144/6 "2025-08-19T13:47:01Z")

</div>

But another problem: I added this for performance in resetAllPos function :

```javascript
function resetAllPos() {

    playerLeft.forEach((pl, i) => {
       if (pl && pl?.physicsBody) {
           pl.physicsBody.setAngularVelocity(Vector3.Zero());
           pl.physicsBody.setLinearVelocity(Vector3.Zero());
           pl.physicsBody.setMotionType(PhysicsMotionType.STATIC);
           pl.physicsBody.disablePreStep = false;
           pl.position = playerPosL[i].clone()
           scene.onAfterRenderObservable.addOnce(() => {
            if (pl && pl?.physicsBody)
              pl.physicsBody.disablePreStep = true;
          })
     }
})

```

However, the reset function doesn’t work after this.

---

<div class="post-metadata">

**Author:** ![mmhosein.hp](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/mmhosein.hp/32/46314_2.png) [@mmhosein.hp](https://forum.babylonjs.com/u/mmhosein.hp)\
**Post date:** [August 19, 2025, 1:56pm UTC](https://forum.babylonjs.com/t/issue-with-resetting-mesh-position-when-using-new-vector3-in-array/60144/7 "2025-08-19T13:56:26Z")

</div>

I replaced `onAfterPhysicsObservable` with `onAfterRenderObservable`, and it worked.
