# Object.layers is undefined when raycasting

**URL:** <https://discourse.threejs.org/t/object-layers-is-undefined-when-raycasting/68101>\
**Category:** Questions\
**Created:** [July 13, 2024, 11:03am UTC](https://discourse.threejs.org/t/object-layers-is-undefined-when-raycasting/68101 "2024-07-13T11:03:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![xertendsz](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/xertendsz/32/43582_2.png) [@xertendsz](https://discourse.threejs.org/u/xertendsz)\
**Post date:** [July 13, 2024, 11:03am UTC](https://discourse.threejs.org/t/object-layers-is-undefined-when-raycasting/68101/1 "2024-07-13T11:03:00Z")

</div>

When attempting to perform raycasting for collision detection, I’m getting an error that says “object.layers is undefined”.

```javascript
private collision(dir: THREE.Vector3, amount: number) {
    const ray = new THREE.Raycaster(this.model.position, dir, 0, amount);
    const colliders = ray.intersectObjects(this.walls, false);
    return (colliders.length > 0 && colliders[0].distance - 0.5 < amount);
}

```

My model is of type `THREE.Group<THREE.Object3DEventMap> | THREE.AnimationObjectGroup` and the walls is an array of `THREE.Object3D<THREE.Object3DEventMap>`

---

<div class="post-metadata">

**Author:** ![Rex\_Dev](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/rex_dev/32/49380_2.png) [@Rex\_Dev](https://discourse.threejs.org/u/Rex_Dev)\
**Post date:** [July 14, 2024, 3:02pm UTC](https://discourse.threejs.org/t/object-layers-is-undefined-when-raycasting/68101/2 "2024-07-14T15:02:19Z")

</div>

I think the error occurs from `this.walls`  
Please check if `this.walls` is true and test again.  
And the second parameter of intersectObjects is recursive. You’re passing false, which means it won’t check children of the objects. If your walls have child objects that you want to include in the collision check, consider changing this to true.  
This is just my opinion and I hope this will be helpful to your issue.
