Search Unity

  1. We would like to hear your feedback about Unity and our products. Click here for more information.
    Dismiss Notice

AR Core failing to find planes

Discussion in 'AR' started by PatrickReynolds, May 8, 2019.

  1. PatrickReynolds

    PatrickReynolds

    Joined:
    Nov 19, 2014
    Posts:
    17
    I am trying to set up a very simple AR Core scene for work, and for some reason the app fails to find any planes. The only type of ARRaycastHit it finds are feature points.

    I have a simple scene with the ARSession and ARSessionOrigin objects, a quad for indicating the placement point, and a gameobject for holding my interaction function. (There's also a canvas with text for debug output.)

    Unity version: 2018.3.0f.2
    AR Foundation: 1.0.0-preview.22
    ARCore XR Plugin: 1.0.0-preview.24
    ARKit XR Plugin: 1.0.0-preview.27

    Here's the code I'm using to locate planes and move my location indicator.

    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using UnityEngine;
    5. using UnityEngine.XR.ARFoundation;
    6. using UnityEngine.Experimental.XR;
    7. using System;
    8. using UnityEngine.UI;
    9.  
    10. public class ARTapToPlaceObject : MonoBehaviour
    11. {
    12.     public GameObject placementIndicator;
    13.     public Text debugString;
    14.  
    15.     private ARSessionOrigin arOrigin;
    16.     private Pose placementPose;
    17.     private bool placementPoseIsValid = false;
    18.  
    19.     // Start is called before the first frame update
    20.     void Start()
    21.     {
    22.         arOrigin = FindObjectOfType<ARSessionOrigin>();
    23.     }
    24.  
    25.     // Update is called once per frame
    26.     void Update()
    27.     {
    28.         UpdatePlacementPose();
    29.         UpdatePlacementIndicator();
    30.     }
    31.  
    32.     private void UpdatePlacementPose()
    33.     {
    34.         var screenCenter = Camera.current.ViewportToScreenPoint(new Vector3(0.5f,0.5f));
    35.         var hits = new List<ARRaycastHit>();
    36.  
    37.         arOrigin.Raycast(screenCenter, hits, TrackableType.All);
    38.  
    39.         placementPoseIsValid = hits.Count > 0;
    40.  
    41.         if (placementPoseIsValid)
    42.         {
    43.             placementPose = hits[0].pose;
    44.             debugString.text = hits[0].pose.position.ToString() + ","  + hits[0].hitType;
    45.         } else
    46.         {
    47.             debugString.text = "No valid placement surface";
    48.         }
    49.     }
    50.  
    51.     private void UpdatePlacementIndicator()
    52.     {
    53.         if (placementPoseIsValid)
    54.         {
    55.             placementIndicator.SetActive(true);
    56.             placementIndicator.transform.SetPositionAndRotation(
    57.                 placementPose.position, placementPose.rotation);
    58.         } else
    59.         {
    60.             placementIndicator.SetActive(false);
    61.         }
    62.  
    63.     }
    64. }
    65.  
    The code works perfectly when it finds a feature point, but that's all it will find.
     
  2. PatrickReynolds

    PatrickReynolds

    Joined:
    Nov 19, 2014
    Posts:
    17
    I just tried this project out with a different version of Unity and ran into the same problem. It finds feature points just fine, but cannot seem to determine where flat surfaces are.

    This attempt:
    Unity: 2019.1.0a12
    AR Foundation: 1.1.0-preview.6
    ARCore XR Plugin: 1.0.0-preview.24
    ARKit XR Plugin: 1.0.0-preview.27
     
  3. t7sika00

    t7sika00

    Joined:
    Jun 3, 2019
    Posts:
    2
    I am using:
    Unity: 2019.1.0f2
    AR Foundation: 2.1.0-preview.3
    ARCore XR Plugin: 2.1.0-preview.5
    ARKit XR Plugin: 2.1.0-preview.5

    and I have exactly same problem. Any ideas on why and how to fix this?