Search Unity

How to make custom prefabs saved to World map?

Discussion in 'AR' started by PunchCircle, Jan 23, 2020.

  1. PunchCircle

    PunchCircle

    Joined:
    Jul 8, 2019
    Posts:
    12
    So, I want to implemented AR for place like museum, and I want to using ARKit 3 World Map function.
    My question is how can I make a custom prefab that can be saved together with World map? For example is custom 3D model.

    So far no matter what I add to my prefab, only the plane from plane detection that is saved to world map.
    Is there any tutorial about this?

    Thank you very much for any help!
     
  2. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    199
    Make anchors and instantiate objects according to them
     
  3. PunchCircle

    PunchCircle

    Joined:
    Jul 8, 2019
    Posts:
    12
    Thank you for your reply. I will try that.

    Edit:
    So I tried and it is not worked.
    When I restart the app, and load the world map, all my instantiated is gone.
    Another question is the anchor name also saved to world map? Or it is just location and rotation?

    I use this code:
    Code (CSharp):
    1.  
    2. if (Input.touchCount > 0)
    3.         {
    4.             Touch touch = Input.GetTouch(0);
    5.  
    6.             if (touch.phase == TouchPhase.Began)
    7.             {
    8.                 if (m_RaycastManager.Raycast(touch.position, s_Hits, TrackableType.PlaneWithinPolygon))
    9.                 {
    10.                     Pose hitPose = s_Hits[0].pose;
    11.  
    12.                     spawnedObject = Instantiate(m_PlacedPrefab, hitPose.position, hitPose.rotation);
    13.                     var anchor = m_ARAnchorManager.AddAnchor(hitPose);
    14.                     if (anchor == null)
    15.                     {
    16.                         Logger.Log("Error creating anchor");
    17.                     }
    18.                     spawnedObject.transform.parent = anchor.transform;
    19.                
    20.  
    21.                     if (onPlacedObject != null)
    22.                     {
    23.                         onPlacedObject();
    24.                     }
    25.                 }
    26.             }
    27.  
     
    Last edited: Jan 24, 2020
  4. unnanego

    unnanego

    Joined:
    May 8, 2018
    Posts:
    199
    When you make an anchor, it is given a name. You can access it by accessing it's properties. When you reinstantiate a downloaded worldmap, you grab all the newly created anchors and reinstantiate objects according to the names of the anchors. You can store the dictionary as a json.

    P.S. Judging from your reply, you seem to have expected it to work automatically - it won't, you have to do Instantiate() on each object.
     
  5. skynnard

    skynnard

    Joined:
    Nov 20, 2020
    Posts:
    3
    I am new to Unity. I am following a tutorial that allows me to save an ARWorldMap. Does Unity have tutorials to follow according to your description above about reinstantiating and accessing an anchors properties to add content to it?