Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question ARFoundation: How to attach Objects to 1 CloudAnchor and then Resolve all Objects with AnchorID?

Discussion in 'AR/VR (XR) Discussion' started by marrosic, Aug 27, 2020.

  1. marrosic

    marrosic

    Joined:
    Jan 11, 2020
    Posts:
    3
    Hi commUnity ,

    I'm trying to use the CodeLabs Example "ARCore Extensions for AR Foundation: Cloud Reference Points" on Android. The ARCore CloudAnchor Example never worked for me, even if I tried to use it with 2 devices simultaneously. That is why I'm trying to work with ARFoundation, but I can't really find a lot of information on CloudAnchors.
    I want to be able to instantiate objects on a Touch, so when I instantiate an Anchor also to use "SetParent(m_cloudAnchor.transform, true) to attach the objects to the Cloud Anchor. Afterwards I would like to use the CloudAnchorID and resolve the anchor with ChildObjects. I'm just not sure if this is actually possible or if I have to have every single object as an anchor and then to save the cloudanchorID's from every single one.

    This is how I think I can attach the Anchor to GameObjects:
    Code (CSharp):
    1. if (cloudAnchorState == CloudAnchorState.Success)
    2.             {
    3.               GameObject cloudAnchor = Instantiate(  HostedPointPrefab, Vector3.zero,Quaternion.identity);
    4.              
    5.              
    6.                 cloudAnchor.transform.SetParent(m_cloudAnchor.transform, false);
    7.                 m_cloudAnchorId = m_cloudAnchor.cloudAnchorId;
    8.              
    9.            
    10.                 foreach(GameObject NewObjects in _addObjects.InstantiatedObjects){
    11.                      NewObjects.transform.SetParent(m_cloudAnchor.transform, true);
    12.                 }
    Also, when at resolving the CloudAnchor from the ID, I'm not sure how to Instantiate all the ChildObjects from the previous code.

    I'm using Unity 2019.3.15f1 and AR Foundation 4.0.2 with ARCore Extensions 1.18.0 and AR XR Plugin 4.0.4


    I would really appreciate any help!