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 Object Tracking with ARKit on iPhone

Discussion in 'AR' started by nathanjams, May 11, 2024.

  1. nathanjams

    nathanjams

    Joined:
    Jul 27, 2016
    Posts:
    305
    Hello,

    Trying out the Object Tracking but need some guidance - new to iOS development.

    I have my prefab being instantiated into the scene when the world onject is detected however the object satys in a fixed position. Is it possible to anchor it to the world object as well?

    What I am trying to do is have a cup in the real world that is scanned by the phone and have a 3d model of the same cup appear in the scene. Ideally, I would like to be able to scale the virtial cup the real world cup and have the virtual cup constantly updating its position to match that of the real world cup.

    Is this possible? Any tips, links or suggestions on how to achieve this? Also, if there is a third party asset that does that even better.

    Much thanks in advance.
    Nathan
     
  2. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,135
    Yes. If you are only tracking one object, a cheap way to do this is to set the Tracked Object Prefab field of the ARTrackedObjectManager. https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@6.0/manual/features/object-tracking.html

    For multiple objects, you'll want to subscribe to the ARTrackedObjectManager's
    trackedObjectsChanged
    event, then choose which prefab you want to spawn based on which object was added. This event passes you an ARTrackedObject, then you should Instantiate your textured mesh prefab as a child of the ARTrackedObject GameObject to ensure that the mesh position is updated via tracking.

    https://docs.unity3d.com/Packages/c..._ARTrackedObjectManager_trackedObjectsChanged