Search Unity

Bug Google Cloud Anchors & ARCoreExtensions integration

Discussion in 'AR' started by Meijer, Jan 12, 2023.

  1. Meijer

    Meijer

    Joined:
    Jun 11, 2015
    Posts:
    15
    Project explanation:
    I'm trying to set up Google Cloud Anchors using this API (although it's already deprecated, am already using the new ARCore API). I started off by using one of Dilmer Valencios's tutorials (the video tutorial and the most important scripts) but it's already 2 years old and therefore rather outdated. In his tutorial, he makes use of an additional Google Package (ARCoreExtensions), which I downloaded from their git repo.

    Problem:
    The problem I'm having is after calling
    HostAnchor()
    in ARCloudAnchorManager, it silently breaks when requesting the quality of the "FeatureMap", with a camera pose (position & rotation) as function parameter. It does not log the statement at line 21.

    When logging
    anchor.sessionID
    , it returns "00000000-0000-0000-0000-000000000000" and in several of the anchor hosting methods (for example in HostCloudAnchor()), there is a check for
    ARCoreExtensions._instance.currentARCoreSessionHandle == IntPtr.Zero
    .
    I imagine that the SessionHandle is the same as sessionID. So that would mean the AR Session does not exist, while at the same time I am able to place AR objects perfectly fine.

    The AR Session object I have is the only one in the scene so it's not an issue of multiple instances clashing.

    Code (CSharp):
    1. public void QueueAnchor(ARAnchor anchor)
    2.     {
    3.         _pendingHostAnchor = anchor;
    4.         Logger.Log($"Received queuing request for {anchor.trackableId}.");
    5.     }
    6.  
    7.     public void HostAnchor()
    8.     {
    9.         Logger.Log($"ARAnchorManager null?: {_arAnchorManager == null}. Anchor null?: {_pendingHostAnchor == null}.");
    10.  
    11.         Pose camPose = GetCameraPose();
    12.         Logger.Log($"Campose: {camPose}.");
    13.  
    14.         FeatureMapQuality quality = FeatureMapQuality.NotProvided;
    15.         Logger.Log($"Initialized quality map: {quality}.");
    16.         quality = _arAnchorManager.EstimateFeatureMapQualityForHosting(camPose);
    17.         Logger.Log($"Quality of feature map is: {quality}.");
    18.         Logger.Log($"Pending host anchor: {_pendingHostAnchor.trackableId}.");
    19.  
    20.         _cloudAnchor = _arAnchorManager.HostCloudAnchor(_pendingHostAnchor, 1);
    21.         Logger.Log($"Resulted cloud anchor: {_cloudAnchor.trackableId}.");
    22.  
    23.         if (_cloudAnchor == null)
    24.         {
    25.             Logger.Log($"Failed to host cloud anchor ({anchorIDToResolve}) at HostAnchor()");
    26.         }
    27.         else
    28.         {
    29.             Logger.Log($"Anchor hosting in progress = true");
    30.             _anchorHostInProgress = true;
    31.         }
    32.  
    33.         Resolve();
    34.     }
    The function called in
    HostAnchor()
    at line 20

    Code (CSharp):
    1.  
    2. public static ARCloudAnchor HostCloudAnchor(
    3.             this ARAnchorManager anchorManager, ARAnchor anchor, int ttlDays)
    4.         {
    5.             if (ARCoreExtensions._instance.currentARCoreSessionHandle == IntPtr.Zero ||
    6.                 anchor == null || anchor.nativePtr == IntPtr.Zero ||
    7.                 anchor.AnchorHandle() == IntPtr.Zero)
    8.             {
    9.                 return null;
    10.             }
    11.             if (ttlDays <= 0 || ttlDays > 365)
    12.             {
    13.                 Debug.LogErrorFormat("Failed to host a Cloud Anchor with invalid TTL {0}. " +
    14.                     "The lifetime of the anchor in days must be positive, " +
    15.                     "the maximum allowed value is 1 when using an API Key to authenticate with " +
    16.                     "the ARCore Cloud Anchor service, otherwise the maximum allowed value is 365.",
    17.                     ttlDays);
    18.                 return null;
    19.             }
    20.  
    21.             // Create the underlying ARCore Cloud Anchor with given ttlDays.
    22.             IntPtr cloudAnchorHandle = SessionApi.HostCloudAnchor(
    23.                 ARCoreExtensions._instance.currentARCoreSessionHandle,
    24.                 anchor.AnchorHandle(), ttlDays);
    25.             if (cloudAnchorHandle == IntPtr.Zero)
    26.             {
    27.                 return null;
    28.             }
    29.  
    30.             // Create the GameObject that is the Cloud Anchor.
    31.             ARCloudAnchor cloudAnchor =
    32.                 new GameObject(_cloudAnchorName).AddComponent<ARCloudAnchor>();
    33.             if (cloudAnchor)
    34.             {
    35.                 cloudAnchor.SetAnchorHandle(cloudAnchorHandle);
    36.             }
    37.  
    38.             // Parent the new Cloud Anchor to the session origin.
    39.             cloudAnchor.transform.SetParent(
    40.                 ARCoreExtensions._instance.SessionOrigin.trackablesParent, false);
    41.  
    42.             return cloudAnchor;
    43.         }
    44.  
    I'm quite sure my application is connected to the Google services, as the hosting requests are shown in the Google dashboard:
    upload_2023-1-11_16-48-35.png upload_2023-1-11_16-48-35.png

    Expected to happen:
    What I'm expecting to happen is an ID being returned other than the collection of zeroes mentioned earlier, so it passes the "IntPtr.zero" check, and after that, move on with the hosting process.

    API versions etc:
    Unity: 2023.1.0a16 (at first 2021.3.15f1, then I tried the Google samples project which required the 2023 version)
    ARFoundation: 5.1.0-pre.2
    ARCore: 5.1.0-pre.2
    ARCore Extensions: 1.35.0

    Please let me know if I should add more information or if I should try to explain something more clearly.
     
    Last edited: Jan 12, 2023
  2. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
  3. DipannitaD

    DipannitaD

    Joined:
    Dec 22, 2021
    Posts:
    1

    @andyb-unity
    As per this page https://developers.google.com/ar/develop/unity-arf/getting-started-extensions
    ARCore Extensions requires AR Session Origin, with AR Foundation 5.0.4 AR Session Origin has replaced with XR Origin and can not assigned to Session Origin of ARCore Extensions. How to resolve this?
    • Session Origin: Use your scene's AR Session Origin.
    upload_2023-3-9_16-7-35.png
     
  4. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    As far as I know Google has not yet upgraded to AR Foundation 5. You are locked into AR Foundation 4.2 for now if you are using ARCore Extensions.
     
  5. frankschifflotte

    frankschifflotte

    Joined:
    Apr 27, 2023
    Posts:
    1
    Please read this: https://developers.google.com/ar/develop/unity-arf/update-to-ar-foundation-5
     
    andyb-unity likes this.