# Issue with Raycasting on Trackable Planes in Magic Leap 2

**URL:** <https://forum.magicleap.cloud/t/issue-with-raycasting-on-trackable-planes-in-magic-leap-2/5293>\
**Category:** OpenXR\
**Created:** [March 4, 2025, 2:12pm UTC](https://forum.magicleap.cloud/t/issue-with-raycasting-on-trackable-planes-in-magic-leap-2/5293 "2025-03-04T14:12:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabrizio.sangiorgi](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@fabrizio.sangiorgi](https://forum.magicleap.cloud/u/fabrizio.sangiorgi)\
**Post date:** [March 4, 2025, 2:12pm UTC](https://forum.magicleap.cloud/t/issue-with-raycasting-on-trackable-planes-in-magic-leap-2/5293/1 "2025-03-04T14:12:40Z")

</div>

**Unity Editor version** 2022.3.47f1:  
**ML2 OS version** : 1.12.0  
**MLSDK version** : 2.6.0

Hi everyone,

I am developing an application for **Magic Leap 2** where I scan the environment for planes using the **sample scene** provided. Once the plane detection is complete, I stop the scanning process and attempt to use **raycasting** to interact with the detected plane.

However, I am facing some issues:

- When using the **controller pointer** , it **passes through the detected plane** , making interaction difficult.
- If I enable a **mesh** , the pointer does not pass through, but I am **unable to instantiate a sphere** on the detected plane or mesh.

I would like guidance on how to correctly **use raycasting** to detect trackable planes and instantiate objects at the intersection point.

Here are my current SDK versions:

**ML2SDK** : 2.6.0  
**OpenXR** : 1.13.0  
**AR Foundation** : 5.1.6

Any insights or suggestions would be greatly appreciated!

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![kbabilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/kbabilinski/32/19_2.png) [@kbabilinski](https://forum.magicleap.cloud/u/kbabilinski)\
**Post date:** [March 4, 2025, 4:47pm UTC](https://forum.magicleap.cloud/t/issue-with-raycasting-on-trackable-planes-in-magic-leap-2/5293/2 "2025-03-04T16:47:31Z")

</div>

You may need to change the layer that the panes are on. You may also need to add a mesh collider to the plane.

Unfortunately, it’s hard to tell directly what might be happening. But we do have this guide that might be helpful.

> **[Mixed Reality Template | MagicLeap Developer Documentation](https://developer-docs.magicleap.cloud/docs/guides/unity-openxr/getting-started/mixed-reality-template/)**
>
> The Unity Mixed Reality Template allows developers to start their projects configured for multi-platform mixed reality development. This guide will walk you through updating the Mixed Reality Template project to work with the Magic Leap 2's Unity...

---

<div class="post-metadata">

**Author:** ![fabrizio.sangiorgi](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@fabrizio.sangiorgi](https://forum.magicleap.cloud/u/fabrizio.sangiorgi)\
**Post date:** [March 6, 2025, 3:06pm UTC](https://forum.magicleap.cloud/t/issue-with-raycasting-on-trackable-planes-in-magic-leap-2/5293/3 "2025-03-06T15:06:20Z")

</div>

Hello,

I tried your approach, but it doesn’t seem to work. Let me explain my issue simply.

I am performing plane detection using the Magic Leap 2 sample project, and I can successfully see the detected planes. Now, I want to draw a rectangle on the detected plane using the controller. My approach is to cast four spheres on the plane and then use a **Line Renderer** to connect the points.

However, I am facing an issue with **Raycasting in Magic Leap 2** :

1. I am unsure if I am correctly casting the ray using the **trigger button**.
2. Even if the ray is being cast, the detected plane does not seem to recognize it.

I need your help to understand and resolve these issues. Could you guide me on how to properly perform raycasting on detected planes using the controller?

Looking forward to your response.

---

<div class="post-metadata">

**Author:** ![kbabilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/kbabilinski/32/19_2.png) [@kbabilinski](https://forum.magicleap.cloud/u/kbabilinski)\
**Post date:** [March 6, 2025, 3:26pm UTC](https://forum.magicleap.cloud/t/issue-with-raycasting-on-trackable-planes-in-magic-leap-2/5293/4 "2025-03-06T15:26:38Z")

</div>

Does the plane have a mesh collider attached to it? Are you simply using physics raycast in Unity? Have you added logs ? (For example log when the raycast hit’s a collider)

---

<div class="post-metadata">

**Author:** ![fabrizio.sangiorgi](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@fabrizio.sangiorgi](https://forum.magicleap.cloud/u/fabrizio.sangiorgi)\
**Post date:** [March 10, 2025, 9:04am UTC](https://forum.magicleap.cloud/t/issue-with-raycasting-on-trackable-planes-in-magic-leap-2/5293/5 "2025-03-10T09:04:18Z")

</div>

Yes, the plane does have mesh collider attach to it. I make no changes to the sample from magic leap2 SDK. but still the pointer ray passes through the plane. Also I tried both methods, AR raycast and Physics Raycast, non of them works.

---

<div class="post-metadata">

**Author:** ![kbabilinski](https://sea1.discourse-cdn.com/flex019/user_avatar/forum.magicleap.cloud/kbabilinski/32/19_2.png) [@kbabilinski](https://forum.magicleap.cloud/u/kbabilinski)\
**Post date:** [March 10, 2025, 2:59pm UTC](https://forum.magicleap.cloud/t/issue-with-raycasting-on-trackable-planes-in-magic-leap-2/5293/6 "2025-03-10T14:59:51Z")

</div>

Hmm, it sounds like a tricky problem. Can you verify that you get the results you are expecting when using the physics raycast on a cube or other 3d mesh?

---

<div class="post-metadata">

**Author:** ![fabrizio.sangiorgi](https://avatars.discourse-cdn.com/v4/letter/f/a4c791/32.png) [@fabrizio.sangiorgi](https://forum.magicleap.cloud/u/fabrizio.sangiorgi)\
**Post date:** [March 11, 2025, 1:07pm UTC](https://forum.magicleap.cloud/t/issue-with-raycasting-on-trackable-planes-in-magic-leap-2/5293/7 "2025-03-11T13:07:15Z")

</div>

Hello,

I have resolved the issue. I set up a new project and added the **AR Raycast Manager** , along with debug logs for troubleshooting. As a result, I can now see the detected plane.

Using the **trigger button** , I instantiate a **sphere** on the plane. However, the sphere does not align with the controller’s pointer; instead, it always spawns with an offset.

Below is the simple logic I used for raycasting:

void Update()  
{  
// Get the controller pointer position & rotation  
Vector3 pointerPos = pointerPosition.action.ReadValue();  
Quaternion pointerRot = pointerRotation.action.ReadValue();

```
    Ray ray = new Ray(pointerPos, pointerRot * Vector3.forward);

    // AR raycast
    if (arRaycastManager.Raycast(ray, arHits, TrackableType.PlaneWithinPolygon))
    {
        Pose hitPose = arHits[0].pose;

        // (Trigger Pressed)
        if (triggerPressed.action.WasPressedThisFrame() && !shapeClosed)
        {
            PlacePoint(hitPose.position);
        }
    }
}

```

Could you help me understand why this offset occurs and how to properly align the sphere with the controller’s pointer?
