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 :
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
}
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+:
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: