Search Unity

Question How to destroy an tracked image when using ar foundation?

Discussion in 'AR' started by blackbookuser, Jul 28, 2021.

  1. blackbookuser

    blackbookuser

    Joined:
    Aug 29, 2017
    Posts:
    5
    Hi! I am a bit stumped since the documentation says the following:

    You should never Destroy a trackable component or its GameObject directly. For trackables that support manual removal, their manager provides a method to remove it. For example, to remove an anchor, you need to call RemoveAnchor on the ARAnchorManager.
    https://docs.unity3d.com/Packages/com.unity.xr.arfoundation@4.1/manual/trackable-managers.html

    But I can't find a method for destroying tracked images in the trackedImage manager, leaving me wondering how I am supposed to actually go about cleaning up AR stuff, if my scene is running for longer periods of time, generating new image markers that should be cleaned up an no longer tracked.

    Any help is appreciated :)
     
  2. KyryloKuzyk

    KyryloKuzyk

    Joined:
    Nov 4, 2013
    Posts:
    1,142
    You don't have to do any cleaning yourself. If your app is designed to track many reference images, you can split them into multiple reference image libraries and select the one that is currently needed. Setting a new image library (or null) to the ARTrackedImageManager.referenceLibrary will clean resources from the old image library.
     
    andyb-unity likes this.
  3. ilya_m_3ds

    ilya_m_3ds

    Joined:
    Jan 15, 2020
    Posts:
    9
    Bump for this question. I also would like to destroy gameobjects generated from tracked image manager in order to conserve memory, however its unclear how to do this. In my case I am only using one reference image library so it doesnt make sense to change the reference in order to force a cleanup.
     
  4. lillie_aardman

    lillie_aardman

    Joined:
    Jan 8, 2019
    Posts:
    1
    Is there an update on this at all? Anyone figured out how to do it?
     
  5. Sennicam

    Sennicam

    Joined:
    Jul 22, 2017
    Posts:
    1
    I have tried setting the referenceLibrary variable, but it is not clearing the old tracked targets.
            _aRTrackedImageManager.referenceLibrary = null;
    _aRTrackedImageManager.referenceLibrary = _imageLibrary;


    This appears to do nothing... I have also tried CreateRuntimeLibrary() and SetTrackablesActive(), but neither gives the behavior I want.

    What I am looking for is to clear out the tracked images, but if an image is seen again, it should come back.

    Everything I have tried either leaves all the tracked images or removes them all permanently.

    I am using:
    • Unity 2020.3.26f1
    • AR Foundation 4.1.10
    • ARCore 4.1.10
    Any help would be appreciated.
     
    luvcraft likes this.
  6. andyb-unity

    andyb-unity

    Unity Technologies

    Joined:
    Feb 10, 2022
    Posts:
    1,062
    Image trackables can only be added or removed by your AR Foundation provider (ie, ARCore or ARKit). If you wish to hide your tracked image content, I recommend deactivating the trackable GameObjects (
    ARTrackedImageManager.trackables
    ), then re-activating them later based on the application logic you are implementing.
     
  7. rsauchuck-gp

    rsauchuck-gp

    Joined:
    Jan 21, 2020
    Posts:
    17
    Are you trying to remove the actual tracked images or the content that spawns when a tracked image is recognized?