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();
}
}
}
How to call Asset Bundle Models after image tracking
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.
How to call Asset Bundle Models after image tracking
Thanks very much, that worked for me very well.
How to call Asset Bundle Models after image tracking
Hi,
From David's post;
How to call Asset Bundle Models after image tracking
Are you attempting to download the asset once the target is found, or are you preloading and want to associate the asset with a target and have it rendered only when the target is detected?
How to call Asset Bundle Models after image tracking
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...
How to call Asset Bundle Models after image tracking
Are you reloading the asset bundle in the second run of the app?
It's hard to guess, but be sure that rendering for those assets is disabled when your app starts - so they won't appear.
How to call Asset Bundle Models after image tracking
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...
How to call Asset Bundle Models after image tracking
I recommend using the simpler Cloud Reco sample, not Books - take a look at books if you want to see how to call out to your own webserver in response to a query result, but start your project in the more basic sample project.
How to call Asset Bundle Models after image tracking
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...
How to call Asset Bundle Models after image tracking
Just to update.. got the cloud to work now :D
scanning is expensive :P it runs like water :D
Hello!
Hello!
Hello YamanakaYue
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