# Imported animated model onclick not working

**URL:** <https://discourse.threejs.org/t/imported-animated-model-onclick-not-working/45932>\
**Category:** Questions\
**Tags:** materials, textures\
**Created:** [December 18, 2022, 7:59pm UTC](https://discourse.threejs.org/t/imported-animated-model-onclick-not-working/45932 "2022-12-18T19:59:50Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ttoomas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ttoomas/32/31869_2.png) [@ttoomas](https://discourse.threejs.org/u/ttoomas)\
**Post date:** [December 18, 2022, 7:59pm UTC](https://discourse.threejs.org/t/imported-animated-model-onclick-not-working/45932/1 "2022-12-18T19:59:51Z")

</div>

Hello. I’m playing around Three.js and ran into a problem. I’m importing a .glb model I created in blender. Then in the onclick handler I write the mesh to the console using raycastre and intersects. Everything works great, but the problem comes after I try to click on the animated walking character. Threejs acts as if it is not there and writes the name of the mesh below it to the console. Does anyone know how to fix this? Thanks.

Entire code can be found on github: [GitHub - ttoomas/brumbalov-game: brumbalov-game](https://github.com/ttoomas/brumbalov-game) Model can be found also on github: [brumbalov-game/final-dambuldor.glb at 2851c865a92dea7b3ff807778e9b7d8c701d1d50 · ttoomas/brumbalov-game · GitHub](https://github.com/ttoomas/brumbalov-game/blob/2851c865a92dea7b3ff807778e9b7d8c701d1d50/public/models/final-dambuldor.glb)

Import model code:

```javascript
async function importHouseModel(){
    const houseGLTF = await gltfLoader.loadAsync('/models/final-dambuldor.glb');
    houseObject = houseGLTF.scene;

    homeScene.add(houseObject);
    
    mixer = new THREE.AnimationMixer(houseObject);

    houseGLTF.animations.forEach((clip) => {
        mixer.clipAction(clip).play();
    })
}

```

Onclick handler code:

```javascript
function handleHomeClick(e){
    e.preventDefault();

    homeMouse.x = (e.clientX / window.innerWidth) * 2 - 1;
    homeMouse.y = -(e.clientY / window.innerHeight) * 2 + 1;

    homeRaycaster.setFromCamera(homeMouse, homeCamera);

    console.log(homeScene);

    let intersects = homeRaycaster.intersectObject(houseObject, true);

    if(intersects.length > 0){
        let object = intersects[0].object;

        console.log(object);
    }
}

```

I tried everything possible, import .fbx, different blender settings, etc. Nothing worked.

---

<div class="post-metadata">

**Author:** ![Oxyn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/oxyn/32/12902_2.png) [@Oxyn](https://discourse.threejs.org/u/Oxyn)\
**Post date:** [December 19, 2022, 1:01pm UTC](https://discourse.threejs.org/t/imported-animated-model-onclick-not-working/45932/2 "2022-12-19T13:01:07Z")

</div>

your character is loaded separately and not part of your raycasting scope (wich only target the house objects).

Create an array including both objects` [houseObject, voldemortModel]`. Then use `intersectObjects` (with the “s” in the end) to raycast the array. it should solve your issue.

---

<div class="post-metadata">

**Author:** ![ttoomas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ttoomas/32/31869_2.png) [@ttoomas](https://discourse.threejs.org/u/ttoomas)\
**Post date:** [December 19, 2022, 3:52pm UTC](https://discourse.threejs.org/t/imported-animated-model-onclick-not-working/45932/3 "2022-12-19T15:52:17Z")

</div>

Hello, thanks a lot for your reply. I tried this and it didnt solve my issue. You can see the changes here: [still not working · ttoomas/brumbalov-game@188afe4 · GitHub](https://github.com/ttoomas/brumbalov-game/commit/188afe4753795543cfb47bf4211e557233209beb) . Can you please check it again? Thanks.

---

<div class="post-metadata">

**Author:** ![ttoomas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ttoomas/32/31869_2.png) [@ttoomas](https://discourse.threejs.org/u/ttoomas)\
**Post date:** [December 19, 2022, 4:05pm UTC](https://discourse.threejs.org/t/imported-animated-model-onclick-not-working/45932/4 "2022-12-19T16:05:36Z")

</div>

I just misswrite brumbalObject, but it still doesn’t work, new commit is on github.

---

<div class="post-metadata">

**Author:** ![Oxyn](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/oxyn/32/12902_2.png) [@Oxyn](https://discourse.threejs.org/u/Oxyn)\
**Post date:** [December 19, 2022, 9:56pm UTC](https://discourse.threejs.org/t/imported-animated-model-onclick-not-working/45932/5 "2022-12-19T21:56:20Z")

</div>

It works on my browser. Tried multiple times and it still work.  
But you have something like 2k objects. Try to optimize your scene (merge individual meshes where you can). Seem the first loading is quite chaotic and mess with the controls and raycasting  
three raycasting is slow, never raycast 2k meshes and millions triangles, if only few objects are actually _interactive_.

![image](https://canada1.discourse-cdn.com/flex035/uploads/threejs/original/3X/f/b/fbfdd681bdec3bf146047a977809afabc7f0f2ec.png)

---

<div class="post-metadata">

**Author:** ![ttoomas](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.threejs.org/ttoomas/32/31869_2.png) [@ttoomas](https://discourse.threejs.org/u/ttoomas)\
**Post date:** [December 20, 2022, 5:07am UTC](https://discourse.threejs.org/t/imported-animated-model-onclick-not-working/45932/6 "2022-12-20T05:07:37Z")

</div>

Hello, thanks a lot for you help. Problem was with export in blenden. I played around with settings, now Its working. Thank you for your help.
