# intersectObjects always returns empty array

**URL:** <https://discourse.threejs.org/t/intersectobjects-always-returns-empty-array/46168>\
**Category:** Questions\
**Tags:** raycaster\
**Created:** [December 23, 2022, 10:32pm UTC](https://discourse.threejs.org/t/intersectobjects-always-returns-empty-array/46168 "2022-12-23T22:32:43Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Amine](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/amine/32/23957_2.png) [@Amine](https://discourse.threejs.org/u/Amine)\
**Post date:** [December 23, 2022, 10:32pm UTC](https://discourse.threejs.org/t/intersectobjects-always-returns-empty-array/46168/1 "2022-12-23T22:32:43Z")

</div>

Hello guys,

I’m new with threeJs and i’m working in the three.js editor ([three.js editor](https://threejs.org/editor/)). I’m trying to add an ‘onclick’ event so that it responds when i click on a sphere i created.

Here is my code, i’m a total beginner with this technology so excuse my potential obvious mistakes

```javascript
let planet = this.getObjectByName( 'Planete' );
let sat1 = this.getObjectByName( 'Satellite1' );
let sat2 = this.getObjectByName( 'Satellite2' );
let cam = this.getObjectByName( 'PerspectiveCamera' );
let scence = this.getObjectByName( 'Scene' );
//let g = this.getObjectByName( 'Group' );

cam.lookAt(planet.position)
player.setCamera( cam );

const raycaster = new THREE.Raycaster();
const pointer = new THREE.Vector2();

function onClick( event ) {

	// calculate pointer position in normalized device coordinates
	// (-1 to +1) for both components
	pointer.x = ( event.clientX / window.innerWidth ) * 2 - 1;
	pointer.y = - ( event.clientY / window.innerHeight ) * 2 + 1;

	// update the picking ray with the camera and pointer position
	raycaster.setFromCamera( pointer, cam );
	 raycaster.layers.enableAll()
	// calculate objects intersecting the picking ray
	let intersects = raycaster.intersectObjects( scence.children );
	console.log(intersects) // <----- always returning empty array
	intersects.forEach((i)=>{
		if(i.object.name != "") {
			console.log(i.object.name);
		}
	});
}

function update( event ) {
	

	renderer.render( scence, cam );
}

addEventListener( 'click', onClick);
window.requestAnimationFrame(update);

```

---

<div class="post-metadata">

**Author:** ![tfoller](https://avatars.discourse-cdn.com/v4/letter/t/3e96dc/32.png) [@tfoller](https://discourse.threejs.org/u/tfoller)\
**Post date:** [December 24, 2022, 5:53pm UTC](https://discourse.threejs.org/t/intersectobjects-always-returns-empty-array/46168/2 "2022-12-24T17:53:11Z")

</div>

It’s hard to tell without seeing a live example of your code.  
Can you transfer it from the editor to jsfiddle or codepen?

---

<div class="post-metadata">

**Author:** ![Amine](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/amine/32/23957_2.png) [@Amine](https://discourse.threejs.org/u/Amine)\
**Post date:** [December 24, 2022, 8:52pm UTC](https://discourse.threejs.org/t/intersectobjects-always-returns-empty-array/46168/3 "2022-12-24T20:52:05Z")

</div>

Oh so I fixed my problem. It didn’t have anything to do with my code. But here was the problem in case anyone has this problem while working on the editor :  
So the big menu in the right side of the screen and shifting all the page to the left so my sphere was appearing shifted but the actual coordinates of the sphere were not where they appeared to be.
