# Three.js scene mesh check

**URL:** <https://discourse.threejs.org/t/three-js-scene-mesh-check/29478>\
**Category:** Questions\
**Tags:** scene\
**Created:** [September 1, 2021, 12:13pm UTC](https://discourse.threejs.org/t/three-js-scene-mesh-check/29478 "2021-09-01T12:13:22Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Lighty](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lighty/32/43283_2.png) [@Lighty](https://discourse.threejs.org/u/Lighty)\
**Post date:** [September 1, 2021, 12:13pm UTC](https://discourse.threejs.org/t/three-js-scene-mesh-check/29478/1 "2021-09-01T12:13:22Z")

</div>

Good day.

How can i check if the mesh is added to the scene?  
Something like that.  
if (scene.includes(mesh)){  
console.log(“true”);  
}

---

<div class="post-metadata">

**Author:** ![Chaser\_Code](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/chaser_code/32/20199_2.png) [@Chaser\_Code](https://discourse.threejs.org/u/Chaser_Code)\
**Post date:** [September 1, 2021, 12:19pm UTC](https://discourse.threejs.org/t/three-js-scene-mesh-check/29478/2 "2021-09-01T12:19:56Z")

</div>

Hi! add name to mesh.

```javascript
mesh.name="ammo";
if(scene.getObjectByName("ammo")){
console.log("true");
}

```

---

<div class="post-metadata">

**Author:** ![Lighty](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/lighty/32/43283_2.png) [@Lighty](https://discourse.threejs.org/u/Lighty)\
**Post date:** [September 1, 2021, 12:39pm UTC](https://discourse.threejs.org/t/three-js-scene-mesh-check/29478/3 "2021-09-01T12:39:33Z")

</div>

Thank you! 😀

---

<div class="post-metadata">

**Author:** ![Harold](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/harold/32/32136_2.png) [@Harold](https://discourse.threejs.org/u/Harold)\
**Post date:** [September 1, 2021, 1:04pm UTC](https://discourse.threejs.org/t/three-js-scene-mesh-check/29478/4 "2021-09-01T13:04:37Z")

</div>

`getObjectByName` involves iterating over every object in the scene, which is slow if you have a lot of objects.

If the object is a direct child of the scene, this is _a lot_ faster:

```javascript
if (object.parent === scene) {
    // The object is in the scene.
}

```

If the object is a child of another object, then maybe doing a recursive lookup through the `.parent` property is better. Try to avoid `.traverse` or `getObjectBy***` methods if you already know/have the object.
