Search Unity

  1. Unity 2019.2 is now released.
    Dismiss Notice

AR Foundation question - UnityARHitTestExample

Discussion in 'Handheld AR' started by kamarmack112, Aug 6, 2019.

  1. kamarmack112

    kamarmack112

    Joined:
    Aug 4, 2019
    Posts:
    1
    I am working on a mobile video game using AR Foundation, and have a question about building for iOS:

    Now that the Unity-ARKit plugin on BitBucket is deprecated and we need to use AR Foundation for iOS, what is the functional equivalent of the UnityARKitHitTestExample.cs script that the ARKit plugin previously used?

    I am unable to follow along AR tutorials that reference this script because I am getting error messages such as "The type or namespace ARPoint could not be found"
     
  2. davidmo_unity

    davidmo_unity

    Unity Technologies

    Joined:
    Jun 18, 2019
    Posts:
    12
    There is no `ARPoint` in ARFoundation. There are a plethora of samples for ARFoundation located here:
    https://github.com/Unity-Technologies/arfoundation-samples

    I believe that you are looking for something similar to this:
    https://github.com/Unity-Technologi...es/blob/master/Assets/Scripts/PlaceOnPlane.cs

    Particularly the following lines
    Code (CSharp):
    1.     void Update()
    2.     {
    3.         if (!TryGetTouchPosition(out Vector2 touchPosition))
    4.             return;
    5.  
    6.  
    7.         if (m_RaycastManager.Raycast(touchPosition, s_Hits, TrackableType.PlaneWithinPolygon))
    8.         {
    9.             // Raycast hits are sorted by distance, so the first one
    10.             // will be the closest hit.
    11.             var hitPose = s_Hits[0].pose;
    12.  
    13.  
    14.             if (spawnedObject == null)
    15.             {
    16.                 spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);
    17.             }
    18.             else
    19.             {
    20.                 spawnedObject.transform.position = hitPose.position;
    21.             }
    22.         }
    23.     }
    24.  
    25.  
    26.     static List<ARRaycastHit> s_Hits = new List<ARRaycastHit>();
    27.  
    28.  
    29.     ARRaycastManager m_RaycastManager;
    30. }
    You may need to check against a particular Trackable type

    Additionally the docs for ARFoundation can be found here (where the Raycasting section may be particularly helpful):
    https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@2.2/manual/index.html