Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Cannot display multiple objects in ARCore Extensions

Discussion in 'AR' started by walrus0816, May 4, 2024.

  1. walrus0816

    walrus0816

    Joined:
    Jun 26, 2019
    Posts:
    2
    Unity 2022.3.24f1
    Apple ARKit XR Plugin 5.13
    AR Foundation 5.13
    ARCore Extensions 1.42.0

    I want to display multiple objects at multiple locations (latitude and longitude) using ARCore Extensions. When I attached the following code to an empty GameObject and entered the latitude and longitude in Unity's inspector, multiple objects were displayed at one location (one set of latitude and longitude). Is there a limit to only one display location for AR in ARCore Extensions?
    If you know of any, please let us know.

    Code (CSharp):
    1. using UnityEngine;
    2. using Google.XR.ARCoreExtensions;
    3. using UnityEngine.XR.ARFoundation;
    4. using UnityEngine.XR.ARSubsystems;
    5. using System.Collections.Generic;
    6.  
    7. public class GeoSetting : MonoBehaviour
    8. {
    9.     [System.Serializable]
    10.     public class GeoData
    11.     {
    12.         public GameObject geospatialAssetPrefab; // Prefabrication of objects to be displayed in AR
    13.         public double latitude; // latitude
    14.         public double longitude; // longitude
    15.         public Quaternion quaternion; // revolution
    16.     }
    17.  
    18.     public List<GeoData> geoDatas; // Geodata list to be set up in Inspector
    19.     public AREarthManager earthManager;
    20.     public ARAnchorManager anchorManager;
    21.  
    22.     private Dictionary<GeoData, ARGeospatialAnchor> anchors = new Dictionary<GeoData, ARGeospatialAnchor>();
    23.  
    24.     void Update()
    25.     {
    26.         if (earthManager.EarthTrackingState == TrackingState.Tracking)
    27.         {
    28.             foreach (GeoData geoData in geoDatas)
    29.             {
    30.                 double altitude = earthManager.CameraGeospatialPose.Altitude;
    31.                 ARGeospatialAnchor anchor = anchorManager.AddAnchor(
    32.                     geoData.latitude,
    33.                     geoData.longitude,
    34.                     altitude,
    35.                     geoData.quaternion);
    36.  
    37.                 if (anchor != null && anchor.transform.childCount == 0)
    38.                 {
    39.                     Instantiate(geoData.geospatialAssetPrefab, anchor.transform.position, anchor.transform.rotation, anchor.transform);
    40.                 }
    41.             }
    42.         }
    43.     }
    44.  
    45.     private void OnDestroy()
    46.     {
    47.         foreach (var anchor in anchors.Values)
    48.         {
    49.             if (anchor != null)
    50.             {
    51.                 Destroy(anchor.gameObject);
    52.             }
    53.         }
    54.     }
    55. }
    56.  

    The attached image shows two text objects with different specified latitudes and longitudes being displayed at the same location.
     

    Attached Files:

  2. walrus0816

    walrus0816

    Joined:
    Jun 26, 2019
    Posts:
    2
    Supplemental: I'm using the ARCore Geospatial API!!
    AddAnchor can only place an AR object at a single latitude and longitude? Please let me know if anyone knows!
     
    Last edited: May 4, 2024
  3. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,135