Search Unity

Unityarimageanchor: How To Only Destroy The Generated Prefab By Finding A Different Anchor?

Discussion in 'AR' started by PTW_AR, Apr 12, 2019.

  1. PTW_AR

    PTW_AR

    Joined:
    Jan 13, 2019
    Posts:
    13
    Hey guys,
    I'm currently trying to archieve the following with the UnityARImageAnchor-scene from ARKit 1.5:

    The default setting is: If you loose the imageAnchor the generated prefab ("prefabToGenerate") will be destroyed. I want the prefabToGenerate to remain until you find another imageAnchor. Then it shall be destroyed.

    I wrote a simple function to deactivate the prefab with a button, whereas it doesn't get destroyed by loosing the imageAnchor.

    How to:

    Comment this part out of the GenerateImageAnchor.cs-script:

    else if (imageAnchorGO.activeSelf)
    {
    //imageAnchorGO.SetActive(false); //persistent prefab
    }


    and add another script to the generated prefab parent with the following function:

    public void DeactivatePrefab()
    {
    gameObject.SetActive(false);
    }


    Now it is possible to manually deactivate generated prefabs. They won't be destroyed anymore by loosing the imageAnchor.

    The only thing left to do is to detect if you found another imageAnchor and automatically trigger above function DeactivatePrefab().

    I thought of looking for something that has to do with the amount of simultaniously tracked imageAnchors, but that wasn't helpful. Using a controller should work, but I feel like there is a much easier solution at hand if you simply communicate with the ARKit SDK.

    Any idea how to achieve my desired goal?