# Unable to call ActionManager with castRay

**URL:** <https://forum.babylonjs.com/t/unable-to-call-actionmanager-with-castray/39162>\
**Category:** Bugs\
**Tags:** ray, action\
**Created:** [March 18, 2023, 4:57pm UTC](https://forum.babylonjs.com/t/unable-to-call-actionmanager-with-castray/39162 "2023-03-18T16:57:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bredd](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bredd/32/30816_2.png) [@bredd](https://forum.babylonjs.com/u/bredd)\
**Post date:** [March 18, 2023, 4:57pm UTC](https://forum.babylonjs.com/t/unable-to-call-actionmanager-with-castray/39162/1 "2023-03-18T16:57:16Z")

</div>

Hello,  
My playground: [https://playground.babylonjs.com/#UGIGWU#37](https://playground.babylonjs.com/#UGIGWU#37)

I am trying to create a 3d version of hangman, and so far I have made a moveable character with a PointerLock. I have been using 26 box meshes as my controls for the hangman, with 1 box per letter, but I am having trouble getting rid of the boxes when I click on them. Previously, I created an individual action manager for each box that I used to call from a castRay function, but since then, I made a function to create all of the boxes in a loop rather than doing it manually, and now I don’t know how to call the action manager for each box. All the boxes are under a general action manager. My problem now is I that don’t know what is the problem, my castRay function, or my general action manager, and I don’t know how to fix either. For the general action manager, I might’ve used the wrong function to disable the box, but I don’t know what the right one would be (I started using Babylon yesterday so sorry for my lack of knowledge). For the CastRay function, I don’t know if I’m even calling the mesh that I want to. If you’re wondering how I made the mouse pointer not misfire when clicking elsewhere on the screen to trigger the pointer lock, I created 4 invisible planes that cover every part of the screen except the center, so only the ray from the camera should be registering(lines 216-238). I have been able to shift around my code so that the mouseclick is detected when I put the mouse in the center of the screen, but I would like a cleaner fix that allows me to use the castray function I created.

In summary: I have 26 box meshes that I created with a for loop that are all connected to one action manager, which I would like to click with the crosshair in the center of the screen. But either the general action manager or the castray function I made is faulty, and I do not know what the problem is, or how to fix it. Lines 135-190 are likely where the problem lies.

---

<div class="post-metadata">

**Author:** ![11128](https://avatars.discourse-cdn.com/v4/letter/1/d07c76/32.png) [@11128](https://forum.babylonjs.com/u/11128)\
**Post date:** [March 20, 2023, 4:29am UTC](https://forum.babylonjs.com/t/unable-to-call-actionmanager-with-castray/39162/2 "2023-03-20T04:29:23Z")

</div>

check this [PG](https://playground.babylonjs.com/#UGIGWU#50)  
As a result, it was converted into a case when a hit occurred without the need for an action manager.

the overall problem  
Inside the onPointerObservable event  
I just declared an unknown mesh, not a hit mesh.  
Also, it seems that the action event of the mesh was not declared (I think it was a mistake while simply creating a case).  
If you want to see the pg and change it to a form other than this form, please comment.

---

<div class="post-metadata">

**Author:** ![bredd](https://sea2.discourse-cdn.com/flex024/user_avatar/forum.babylonjs.com/bredd/32/30816_2.png) [@bredd](https://forum.babylonjs.com/u/bredd)\
**Post date:** [March 20, 2023, 5:05am UTC](https://forum.babylonjs.com/t/unable-to-call-actionmanager-with-castray/39162/3 "2023-03-20T05:05:10Z")

</div>

Thank you so much for the solution and explanation! I had resorted to creating each object individually, which was time-consuming, to say the least. I never realized I forgot to declare the action event for the meshes, so this makes me feel a little better. I just started learning JS and using BabylonJS on Thursday, so sorry for the simplistic/newbie question.

---

<div class="post-metadata">

**Author:** ![11128](https://avatars.discourse-cdn.com/v4/letter/1/d07c76/32.png) [@11128](https://forum.babylonjs.com/u/11128)\
**Post date:** [March 20, 2023, 5:52am UTC](https://forum.babylonjs.com/t/unable-to-call-actionmanager-with-castray/39162/4 "2023-03-20T05:52:32Z")

</div>

Asking easy or introductory questions is relative, but I think it’s a good way to jump up faster anyway.
