Search Unity

How to load Scene Asset bundle from a web server

Discussion in 'Web' started by nsmith1024, Dec 9, 2018.

  1. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    Hello,

    I create a scene bundles using this code then upload all the files generated into a folder on the server

    Code (CSharp):
    1.    
    2. [MenuItem("MyMenu/Build AssetBundles WebGL")]
    3.     static void BuildAllAssetBundlesWebGL()
    4.     {
    5.         BuildPipeline.BuildAssetBundles("D:/UnityProjects/AssetBundles", BuildAssetBundleOptions.None, BuildTarget.WebGL);
    6.     }
    I have a base scene that stays loaded all the time, then load new scenes on top of that ADDITIVELY. When i want a new scene i unload the existing scene (the one that was loaded additively) and then additively load in the new scene.

    So here is the code to load in a scene additively

    Code (CSharp):
    1.  
    2.   public IEnumerator LoadSceneBundle(string url, string bundleFileName, string nameInBundle)
    3. {
    4.         WWW www = new WWW(url);
    5.         yield return www;
    6.  
    7.         if (www.assetBundle != null) {
    8.             GlobalData.assetBundle = www.assetBundle;
    9.             string[] scenePath = GlobalData.assetBundle.GetAllScenePaths();
    10.             GlobalData.loadedBundleScene = nameInBundle;
    11.             SceneManager.LoadScene(nameInBundle, LoadSceneMode.Additive);
    12.         }
    13. }


    Here is the code to unload the scene (that was loaded additively) before calling the above code to load in a new scene.


    Code (CSharp):
    1.     IEnumerator UnloadSceneAsync()
    2.     {
    3.         yield return new WaitForSeconds(0.5f);
    4.         yield return new WaitForEndOfFrame();
    5.         AsyncOperation ao = SceneManager.UnloadSceneAsync(GlobalData.loadedBundleScene);
    6.         while (!ao.isDone) {
    7.             yield return new WaitForSeconds(0.2f);
    8.         }
    9.         yield return null;
    10.         SceneUnloaded();
    11.     }
    12.  
    13.     public void SceneUnloaded()
    14.     {
    15.         Debug.Log("SCENE UNLOADED");
    16.     }
    17.  

    The problem is that the code crashes when I try unloading the scene, but it only crashes in WebGL, the same code doesnt crash in the Editor, nor when i build stand alone for Windows.

    Does anybody know why???

    Also Terrains arnt loaded when i load the scene using the above code, everything in the scene is present except for the terrain. The same asset bundle is loaded in the editor and terrains work, and when i build for windows standalone, the terrain also work. So only in WebGL the terrains are missing.

    Im using Unity Version 2018.1.0f2

    Does anybody know how to fix these two problems?
     
  2. nishugu2

    nishugu2

    Joined:
    Nov 24, 2017
    Posts:
    5
    hello i am new in unity and read how the asset bundle load from server.i Create asset bundle of scene by the help of asset bundle browser but get a problem when i load the scene from asset bundle the scene don't get all the game object(No Canvas , No Main Camera and No Event System) will you plz tell me why? and how can i correct it?
     
  3. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    Hello,

    Im new to this UMA, all i need is to have the simplest scene where the user can design a basic character (adjust the DNA, add basic clothes shoes etc), and then able to obtain a string of the recipe so i can save it.

    I dont want anything complicated, just the most simple scene so that it can be as small as possible for a WebGL build so that the user doesnt have to download a giant build everytime they use it.

    Is there any SIMPLE example scene that comes with the stock UMA2 install that i can use for this?

    I tried using the "UMA DCS Demo - USING ASSET BUNDLES" but when built for WebGL it come out to around 200 megabytes (way too big) and that doesnt even include my game, just the UMA design scene (my whole game is only 50 meg including the old UMA character system editor and editing scene), why is the new one so BIG!!?

    Thanks so much!
     
    Last edited: Feb 16, 2019
  4. nsmith1024

    nsmith1024

    Joined:
    Mar 18, 2014
    Posts:
    870
    I imported UMA 2.8 from asset store, and build it for WebGL, but when i upload the build to a server and run it on a browser, the character doesnt show up. I even deleted the UMA folder several times and re-import from scratch, then build, but same result everytime!

    Anybody knows why???