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 ARCORE question regarding the cloning of the ImageTrackedPrefab and leaving it at its current coord

Discussion in 'AR' started by ngajason, May 13, 2024.

  1. ngajason

    ngajason

    Joined:
    Jun 18, 2021
    Posts:
    5
    Hi everyone,

    I am trying to clone (multiple times) the instantiated prefab from Tracked Image Manager and leave it in its current location at the time of a button click. The purpose of this is to produce a heatmap manually by using an OnClick event to take the prefab that is being tracked, clone it, and parent it to an empty GameObject that is parented to the AR camera. I'm doing the parenting in order to (hopefully) leave the cloned prefab at its current location so it isn't tracking anymore.

    The issue I am having is I cannot find the GameObject that is instantiated because ARCORE/ARFoundation gives it a random name in runtime that always appears to start with "ARTrackedImage" followed by alpha-numeric string.

    Is there a way to clone any child of the GameObject "Trackables", clone a gameobject by using a partial name with a GameObject.Find, or is there anyway that you can think of that will allow me to access the prefab instantiated on the TrackedImage to clone it?

    Also, if there is abetter way to clone, Im open to other options. Im using Unity 2021.3.21 and ARFoundation/and ARCore 4.2.7

    My attempt to do this is posted this to the main discussion board, and I think that it will work if I knew the prefab name in order to run a GameObject.Find:

    https://forum.unity.com/threads/arf...d-leave-in-current-state-or-position.1592757/

    Thanks in advance guys! Any help is appreciated.
     
  2. ngajason

    ngajason

    Joined:
    Jun 18, 2021
    Posts:
    5
    Ok, I found this Runtime Inspector plugin which is super helpful for displaying the hierarchy and inspector in my app.

    https://assetstore.unity.com/packages/tools/gui/runtime-inspector-hierarchy-111349#reviews

    I am able to see that I am cloning the prefab that TrackedImageManager is producing (For anyone losing their mind on this ARFoundation naming the prefab name is the same as the prefab and ARFoundation adds "(Clone)" with no space next to the prefab name).

    Its been a long day and my brain isn't computing how the cloned position is correlating with my device camera. It appears to be placing the cloned GO very close to 0,0,0 relative to the device camera. That Im sure is a result of the cloned GO being parented to an empty GO that is a child of my camera. I see the values for position changing for each cloned prefab... but they are not visible to the camera because the coordinates are relative to the AR camera/Device Camera. Each of the clones has a separate and independent set of non-changing values for transform, scale, and rotation.

    Some of my research is pointing to anchors. I don't understand the anchors in ARFoundation enough to know what is happening. Is there a way to set or change the anchor from the child GO to my AR camera and set it to scene/world anchor so that when I move the image around the prefabs sit in different positions? Any help understanding these Anchors is very much appreciated!
     
  3. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,135
    Here you go! https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@5.1/manual/features/anchors.html

    We recommend that you upgrade to AR Foundation 5.1. This package isn't visible in Unity's package manager, but you can upgrade by following this article: https://docs.unity3d.com/Packages/c...project-setup/edit-your-project-manifest.html

    AR Foundation 5 introduces XR Simulation, which allows you to see how the AR Foundation GameObjects work while running your app in the Editor. This should help you quite a bit with understanding how the Trackables GameObject works.

    Using GameObject.Find at runtime is not a great idea for performance reasons. The more GameObjects you have in your scene, the longer this will take! You should subscribe to the
    imagesChanged
    event instead, and use the GameObject passed to you by ARTrackedImageManager when the image is detected. https://docs.unity3d.com/Packages/c...mage-tracking.html#respond-to-detected-images