private IEnumerator LoadSceneFromStream()
{
Caching.CleanCache();
yield return null;
var url = @"...here goes the path ... \Unity\LoadAssetTest\testscene";
using (WWW www = WWW.LoadFromCacheOrDownload(url, 0))
{
while (!www.isDone)
{
status.text = "loading \n" + (www.progress * 100).ToString() + "%";
yield return null;
}
yield return www;
if (www.error != null)
{
Debug.LogErrorFormat("WWW download had an error: {0} - {1}", url, www.error);
}
AssetBundle bundle = www.assetBundle;
//bundle.LoadAllAssets();
Application.LoadLevel("TestScene");
}
}
The problem is that, unless I include scripts on the main project (I mean, the one that loads the remote scenes), I always get the following message on the editor at runtime: “The associated script cannot be loaded. Please fix any compile errors and assign a valid script.”. And on the target platforms (Android in this case, windows standalone, and so on), since scripts are missing, the streammed scene is just loaded with no behaviors.
On this thread it seems someone found a solution which is not working for me. So the question is: can scripts be streamed along/with the scene or not?
So, I guess the answer is no, unless you use reflection where available.
Now, another question: when you build a scene bundle, does it include all assets/dependencies in the scene? Or do you have to build one bundle for the scene itself and a different bundle with its assets?
For a personal use case : We made an asset bundle by just checking all our scenes to go in asset bundles. Then we build the asset bundle, we build a game with just one scene that loads the only one asset bundle, and we decompress the whole game like this.
(“Y did u do dis ?” Because our mobile game is “pretty big” on iOS (160Mb) and our publisher wants to keep the game under 100Mb, so we put the one-simple-scene game on asset store (which is 60Mb… of what ? well… that’s a big question Mr Cook), and we download the whole game during first lunch.)
Everything works fine EXCEPT custom shaders, that I included into the “build-in shaders” into the Graphics menu, if I don’t do this, all my custom shader are broken.
Thanks for the answer. Ah, ok, so I guess you had also to include the custom scripts you use in all your bundled scenes in the one-simple-scene game for them to work, right? (specially on iOS since there afaik there is no emit on the mono framework for that platform).
Scripts aren’t exported in asset bundle, Unity re-assign them automaticly at the right place when you load the asset bundle
Just put your scenes into an asset bundle (without assign any other assets, Unity will do it itself), load it and you’ll see, everything works fine (except custom Shaders, as I said)
Streaming Assets cannot be bundled unless they are converted into .bytes. Then, unless you include them as parameters of a custom script (which forces the exporter to pack them with the scene bundle), you will need to include them in a separated asset bundle since the editor only bundles those assets “In Use” (like textures used in a material assigned to a cube already on the editor’s Hierarchy).