Log in or register to post comments

The object of type 'ImageTargetBehaviour' has been destroyed but you are still trying to access it

November 25, 2013 - 6:32pm #7

Hi there !

I am trying to follow CloudRecoTarget sample with mutiple targets but i got stuck at one point with an error of

"The object of type 'ImageTargetBehaviour' has been destroyed but you are still trying to access it ".  

It seem that object of type of "ImageTargetBehaviour" will always destroy when " OnNewSearchResult " is fire .

In the sample CloudRecoTarget project they have code as in following  but why thier CloudRecoTarget (object of type ImageTargetBehaviour)is not destroy? and while CloudRecoBehaviour is set to false

mCloudRecoBehaviour.CloudRecoEnabled = false;

why they can track another targets?

Hopping for your kindly help. Thanks

 

    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
    {
        // This code demonstrates how to reuse an ImageTargetBehaviour for new search results and modifying it according to the metadata
        // Depending on your application, it can make more sense to duplicate the ImageTargetBehaviour using Instantiate(), 
        // or to create a new ImageTargetBehaviour for each new result

        // Vuforia will return a new object with the right script automatically if you use
        // TargetFinder.EnableTracking(TargetSearchResult result, string gameObjectName)
        
        //Check if the metadata isn't null
        if(targetSearchResult.MetaData == null)
        {
            return;
        }

        // enable the new result with the same ImageTargetBehaviour:
        ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, mParentOfImageTargetTemplate);

        if (imageTargetBehaviour != null)
        {
            // stop the target finder
            mCloudRecoBehaviour.CloudRecoEnabled = false;
            
            // Calls the TargetCreated Method of the SceneManager object to start loading
            // the BookData from the JSON
            mContentManager.TargetCreated(targetSearchResult.MetaData);
        }
    }

 

The object of type 'ImageTargetBehaviour' has been destroyed but

November 25, 2013 - 6:39pm #6

The trackable returned with the Cloud Recognition search result is overwritten by subsequent search results. So only one Cloud Recognition trackable can exist at a time. 

You can track Cloud Recognition targets and Device Database targets simultaneously though.

The object of type 'ImageTargetBehaviour' has been destroyed but

November 25, 2013 - 6:46pm #5

But how the CloudRecoTarget sample does?
I do not see where they clone the ImageTagetTemplate.
Can you explain more clearly please?

The object of type 'ImageTargetBehaviour' has been destroyed but

November 26, 2013 - 8:40am #4

Here is a simpler example of how to handle search results using a template - https://developer.vuforia.com/forum/cloud-recognition/cloud-recognition-tutorial-scripts

Here is the relevant code..

 

public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
    {
        // duplicate the referenced image target
        GameObject newImageTarget = Instantiate(ImageTargetTemplate.gameObject) as GameObject;
         
        GameObject augmentation = null;
         
        string model_name = targetSearchResult.MetaData;
         
         
        if( augmentation != null )
            augmentation.transform.parent = newImageTarget.transform;
 
        // enable the new result with the same ImageTargetBehaviour:
        ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, newImageTarget);
         
        Debug.Log("Metadata value is " + model_name );
         
         
         
        switch( model_name ){
             
            case "teapot" :
                 
                Destroy( imageTargetBehaviour.gameObject.transform.Find("Dragon").gameObject );
                
                break;
             
            case "dragon" :
                 
                Destroy( imageTargetBehaviour.gameObject.transform.Find("teapot").gameObject );
             
                break;
             
        }
 
        if (imageTargetBehaviour != null)
        {
            // stop the target finder
            mCloudRecoBehaviour.CloudRecoEnabled = false;
        }
    }

 

and this tutorial will show you how to set-up a Cloud Reco app that uses this event handler - https://developer.vuforia.com/resources/tutorials/creating-cloud-recognition-apps-unity

 

 

The object of type 'ImageTargetBehaviour' has been destroyed but

January 21, 2014 - 2:09am #3

Thank you for your help DavidBeard

I found the solution to my problems. I did not disable CloudRecoBehaviour while i did not Instantiate(ImageTargetTemplate.gameObject).

Here is what i have come up with.

    public void OnNewSearchResult(TargetFinder.TargetSearchResult targetSearchResult)
    {
 
        // enable the new result with the same ImageTargetBehaviour:
        ImageTargetBehaviour imageTargetBehaviour = mImageTracker.TargetFinder.EnableTracking(targetSearchResult, mParentOfImageTargetTemplate);        
 
        if (imageTargetBehaviour != null)
        {
            // stop the target finder
            mCloudRecoBehaviour.CloudRecoEnabled = false;
            mContentManager.TargetCreated(targetSearchResult.MetaData);
        }
 
    }

And everytime when we want to enable CloudRecoBehaviour we have to check.

if (mCloudRecoBehaviour.CloudRecoInitialized && !mCloudRecoBehaviour.CloudRecoEnabled)
{

  mCloudRecoBehaviour.CloudRecoEnabled = true;

}

The object of type 'ImageTargetBehaviour' has been destroyed but you are still trying to access it

March 24, 2018 - 2:56pm #2

Still have a problem on Cloud Book Sample !!

TargetSearchResult  xxxx could not be enabled for tracking.

Unity3d

Version 2017.3.1f1 (fc1d3344e6ea)

Mon, 29 Jan 2018 15:28:29 GMT

Branch: 2017.3/release



Vuforia 7.0.47

 

AttachmentSize
Image icon 20180325053330.png206.56 KB
Image icon 20180325053436.png46.69 KB
Image icon 20180325053629.png9.41 KB

The object of type 'ImageTargetBehaviour' has been destroyed but you are still trying to access it

March 26, 2018 - 11:01am #1

1966392197 wrote:

Still have a problem on Cloud Book Sample !!

TargetSearchResult  xxxx could not be enabled for tracking.

Unity3d

Version 2017.3.1f1 (fc1d3344e6ea)

Mon, 29 Jan 2018 15:28:29 GMT

Branch: 2017.3/release



Vuforia 7.0.47

 

I am not able to reproduce this. Do you have a license key added to this project? If so, what kind of key?

Thanks,

Vuforia Support

Log in or register to post comments