ARFoundation Raycast on Infinite plane

Hello everybody,

I try to place a gameobject on an ARPlane.
No problem when I make a Raycast on TrackableType.PlaneWithinBounds and I click on the plane.

But nothing happen when I use TrackableType.PlaneWithinInfinity and I click indide or outside the plane.

Someone know how to “convert” my plane to Inifinte plane and raycast outside the bound?

Best,
Alexis

Hi there. I stumbled on the same problem, here is how I did it:

Create a Prefab with a correctly oriented Quad. Give it a big size (I used 50x50x1). Put a material with some transparency for tests. Affect this Prefab to a specific layer (like “InfiinitePlane”).

Create a script where you listen for the “planesChanged” event on the ARPlaneManager and when a plane is detected :

private void OnPlanesChanged(ARPlanesChangedEventArgs evt)
{
    List<ARPlane> addedPlanes = evt.added;
    if (addedPlanes.Count > 0 && m_InfinitePlane == null)
    {
        ARPlane plane = addedPlanes[0];
        Vector3 position = plane.center;
        m_InfinitePlane = Instantiate(m_InfinitePlanePrefab, position, Quaternion.identity);
    }
}

Then, in the script to manage the placement of your GameObject, raycast against your custom infinite plane instead of using the ARFoundation tools with something like this:

Ray ray = Camera.main.ScreenPointToRay(m_CurrentTouchPosition);
RaycastHit hit;
if (Physics.Raycast(ray, out hit, Mathf.Infinity, LayerMask.GetMask("InfinitePlane")))
{
    // Place your GameObject
}

Works like a charm in my project.

Cheers!

There is no need to create an invisible plane. Raycast with TrackableType.PlaneWithinInfinity is intended for this exact purpose.
Could you please tell me your Unity and AR Foundation versions?

Here is an example of raycast on an infinite plane that works with Unity 2019.2+ and AR Foundation 3.0.1+:

Hi,

thanks for this tips!

Best,
Alexis

It turns out ARCore doesn’t support TrackableType.PlaneWithinInfinity, but there is a way to use the
ARPlaneManager.Raycast() as a workaround. Please see this response: