"We offer new support options and therefor the forums are now in read-only mode! Please check out our Support Center for more information." - Vuforia Engine Team

How to call Asset Bundle Models after image tracking

Hello,

I have been able to load models at runtime with Asset Bundles in Unity Pro. However, currently my models load right at runtime instead of after image tracking. After image tracking the correct model will lock to the trackable image and rotate normally but do not dissappear after the trackable image is lost. My question is how to only load the model after image tracking? I am loading the asset bundle models into an empty object that is a child of my ImageTarget. On this empty object I attached the following script, if I use a regular object as a child of my imagetarget it does not show up early only the dynamically pulled objects.

Thank you for any help!

 

 

 

 

using System;

using UnityEngine;

using System.Collections;

 

public class CachingLoadExample : MonoBehaviour {

public string BundleURL;

public string AssetName;

public int version;

 

void Start() {

StartCoroutine (DownloadAndCache());

}

 

IEnumerator DownloadAndCache (){

// Wait for the Caching system to be ready

while (!Caching.ready)

yield return null;

 

// Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache

using(WWW www = WWW.LoadFromCacheOrDownload (BundleURL, version)){

yield return www;

if (www.error != null)

throw new Exception("WWW download had an error:" + www.error);

AssetBundle bundle = www.assetBundle;

if (AssetName == "")

Instantiate(bundle.mainAsset);

else

Instantiate(bundle.Load(AssetName));

                // Unload the AssetBundles compressed contents to conserve memory

                bundle.Unload(false);

 

                       // Frees the memory from the web stream

                       www.Dispose();

}

}

}

 

 

DavidBeard

Mon, 09/02/2013 - 00:16

To accomplish that, I think you'll want to call StartCoroutine (DownloadAndCache()); from Update() instead of Start() and have Update check a boolean that is set from the ImageTargets trackable event handler on the GameObjects script component for this scripts.

 

e.g.

It is working now on the editor but once built on the device... it seems like the loaded assetbundle works like a charm for the first time.... but if the app is opened the second time... the asset bundle is stuck on the screen until the marker is shown...

well.. started this app on the image tracker to test the fetching ability for asset bundle... n slowly got all the pieces to work together...

now i am plannin to move it to the cloud reco scene... which im still confused to use the book demo or the cloud reco sample...

Ok i've already started with the cloud reco sample... now all i gotta do is make sure each image tracked has a metadata in it with url and in the app make sure it uses that metadata to read the url to download dynamically...

Hello YamanakaYue

I have some problem with you. do you found to solve this problem?? if you solve the problem can you post your code.

Thanks. i hope you can hlep me