# Remove method is not working as expected

**URL:** <https://discourse.threejs.org/t/remove-method-is-not-working-as-expected/63957>\
**Category:** Questions\
**Tags:** webxr\
**Created:** [April 11, 2024, 11:24am UTC](https://discourse.threejs.org/t/remove-method-is-not-working-as-expected/63957 "2024-04-11T11:24:13Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![srihari.bg](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@srihari.bg](https://discourse.threejs.org/u/srihari.bg)\
**Post date:** [April 11, 2024, 11:24am UTC](https://discourse.threejs.org/t/remove-method-is-not-working-as-expected/63957/1 "2024-04-11T11:24:13Z")

</div>

Hi, I am attaching an Object3D to the Quest 3 controller in a VR scene, and upon trying to remove it using .remove method , I see no change in the controller children

Here’s what I am trying to do exactly:

```javascript
        container.attach(containerback);
        leftController.controller.attach(container);

```

and

```javascript
         container.remove(containerback);
         leftController.controller.remove(container);

```

In the above snippet containerback is a Box geometry and container is the Object3D  
I am trying to achieve this in React Three Fiber and React Three XR, so leftController is:

```javascript
const leftController = useController('left');

```

Am I missing on some information or does anyone know the reason for this issue?

Any help will be much appreciated!

---

<div class="post-metadata">

**Author:** ![manthrax](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/manthrax/32/2596_2.png) [@manthrax](https://discourse.threejs.org/u/manthrax)\
**Post date:** [April 11, 2024, 11:45am UTC](https://discourse.threejs.org/t/remove-method-is-not-working-as-expected/63957/2 "2024-04-11T11:45:04Z")

</div>

Looks like it should work. Note there is a difference between .add and .attach

Can you post a working reproduction of the issue in a fiddle||codepen||glitch?

---

<div class="post-metadata">

**Author:** ![PavelBoytchev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/pavelboytchev/32/38639_2.png) [@PavelBoytchev](https://discourse.threejs.org/u/PavelBoytchev)\
**Post date:** [April 11, 2024, 12:10pm UTC](https://discourse.threejs.org/t/remove-method-is-not-working-as-expected/63957/3 "2024-04-11T12:10:36Z")

</div>

Did you check (by debugging, tracing, or console.logging) that `counterback` is still a child of `container` at the time of removing? When an object is cloned, the parent-child link is broken.

---

<div class="post-metadata">

**Author:** ![Lawrence3DPK](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lawrence3dpk/32/29184_2.png) [@Lawrence3DPK](https://discourse.threejs.org/u/Lawrence3DPK)\
**Post date:** [April 11, 2024, 12:13pm UTC](https://discourse.threejs.org/t/remove-method-is-not-working-as-expected/63957/4 "2024-04-11T12:13:11Z")

</div>

> [@manthrax](#):
>
> Note there is a difference between .add and .attach

~~Give `detach()` a try rather than `remove()`~~

Or

`add` instead of `attach`…

---

<div class="post-metadata">

**Author:** ![srihari.bg](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@srihari.bg](https://discourse.threejs.org/u/srihari.bg)\
**Post date:** [April 11, 2024, 12:14pm UTC](https://discourse.threejs.org/t/remove-method-is-not-working-as-expected/63957/5 "2024-04-11T12:14:55Z")

</div>

Is there anything as detach in ThreeJS, I could not find any documentation

---

<div class="post-metadata">

**Author:** ![srihari.bg](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@srihari.bg](https://discourse.threejs.org/u/srihari.bg)\
**Post date:** [April 11, 2024, 12:15pm UTC](https://discourse.threejs.org/t/remove-method-is-not-working-as-expected/63957/6 "2024-04-11T12:15:25Z")

</div>

I did console log the controller children and the Object still exists

---

<div class="post-metadata">

**Author:** ![srihari.bg](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@srihari.bg](https://discourse.threejs.org/u/srihari.bg)\
**Post date:** [April 11, 2024, 12:16pm UTC](https://discourse.threejs.org/t/remove-method-is-not-working-as-expected/63957/7 "2024-04-11T12:16:03Z")

</div>

I am afraid I can’t, I am under an NDA

---

<div class="post-metadata">

**Author:** ![PavelBoytchev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/pavelboytchev/32/38639_2.png) [@PavelBoytchev](https://discourse.threejs.org/u/PavelBoytchev)\
**Post date:** [April 11, 2024, 12:28pm UTC](https://discourse.threejs.org/t/remove-method-is-not-working-as-expected/63957/8 "2024-04-11T12:28:52Z")

</div>

The fact that it exists means you did not remove the correct object.

So, try removing the child of the controller, not the variable that holds the object.

As for NDA, there is absolutely no problem to make a small demo program (unrelated to your project) and if the issue persist – share this demo. If the issue is resolved, then compare both code to find where is the issue.

---

<div class="post-metadata">

**Author:** ![Lawrence3DPK](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lawrence3dpk/32/29184_2.png) [@Lawrence3DPK](https://discourse.threejs.org/u/Lawrence3DPK)\
**Post date:** [April 11, 2024, 12:28pm UTC](https://discourse.threejs.org/t/remove-method-is-not-working-as-expected/63957/9 "2024-04-11T12:28:56Z")

</div>

Hey, sorry my mistake, `detach` is a specific internal method of `TransformControls` not `Object3D`, so the answer I gave above is not correct and of course won’t work.

> <https://github.com/mrdoob/three.js/blob/7690b5090676101c5c3818eeadbf92f8fa7c60e1/examples/jsm/controls/TransformControls.js#L583>
