Hello,
I’m working with AR Foundation at the moment and I’m having an issue with returning the TrackableID of the hit ARPlane after an ARRaycast succeeds. Here is the code I’m using:
List<ARRaycastHit> _hits = new List<ARRaycastHit>();
if(_raycastManager.Raycast(new Vector2(Screen.width / 2, Screen.height / 2), _hits, TrackableType.Planes))
{
TrackableId _planeID = _hits[0].trackableId;
print(_planeID);
ARPlane _arPlane = _arPlaneManager.GetPlane(_planeID);
print(_arPlane);
Vector3 _arPlaneNormal = _arPlane.normal;
Vector3 _hitPos = _hits[0].pose.position;
Vector3 _planeProjection = Vector3.ProjectOnPlane(_hitPos, _arPlaneNormal);
Vector3 _camPos = Camera.main.transform.position;
Vector3 _targetPos;
_planesID is null every time even though the Raycast succeeds. How is this even possible?? I would assume that every ARPlane has a TrackableID, regardless of the type of plane (listed below), or is this assumption incorrect??
The expected behaviour after setting the final Raycast arg to TrackableTypes.Planes would be that it returns true if it actually hits a plane and thus there should be a TrackableID available.
In the meantime, I’m going to try to narrow down the TrackableTypes I Raycast against.
If anyone can shed some light on this, I would be grateful and I will report back if it is indeed because of the TrackableTypes of planes.
PlaneEstimated
Refers to an estimated plane.
Planes
Refers to any of the plane type trackables.
PlaneWithinBounds
Refers to the 2D rectangular bounding box that tightly encloses the plane’s polygon.
PlaneWithinInfinity
Refers to the infinite plane described by its Pose (a position and orientation).
PlaneWithinPolygon
Refers to 2D convex shape associated with a plane’s boundary points.