Search Unity

Asset Bundle Scenes Workflow?

Discussion in 'Asset Bundles' started by polytropoi, Jul 18, 2017.

  1. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    I'm trying to adapt to the 2017x way of doing asset bundles, and I think I've got a handle on "normal" bundles, but I also use scene bundles extensively, and I can't seem to find a workflow that lets me build scene bundles and load them from my server. I get different errors depending on whether the Simulation Mode is on (if it's on, I get a "can't find scene with that name in that bundle" error, and with Sim Mode off, I get
    NullReferenceException: Object reference not set to an instance of an object
    AssetBundles.AssetBundleManager.RemapVariantName (System.String assetBundleName) (at Assets/AssetBundleManager/AssetBundleManager.cs:372).

    Here's the load script I'm using atm:
    Code (CSharp):
    1.                 var www = WWW.LoadFromCacheOrDownload (bundleUrl, 1); //{
    2.                 yield return www;
    3.                 if (!string.IsNullOrEmpty (www.error)) {
    4.                     Debug.Log (www.error);
    5.                     yield return null;
    6.                 } else {
    7.                     AssetBundleLoadOperation request = AssetBundleManager.LoadLevelAsync(bundleName, sceneName, true);
    8.                     if (request == null)
    9.                         yield break;
    10.                     yield return StartCoroutine(request);
    For my project (see https://servicemedia.net), I build lots of scene bundles from external projects, along with "normal" bundles that contain only one prefab, across multiple platforms, and host them in the cloud. I had working build scripts and client/server code to support all this, that was kindof making me happy, until 2017.1 came along... Anyway, this might be a bug, if so I'll submit a minimal case, but I could also be Doing It Wrong.
     
    Last edited: Jul 18, 2017
  2. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    I did a bug report, see case 932503. Using the asset bundle manager, in 2017.1f3, I built the TestScene used in the LoadScene demo, and put it on the server, used that link in the way indicated in LoadScene.cs, got the same errors described above.

    Loading scene bundles from a server seems like pretty important general use case; for me it's integral to everything I'm doing. Very disappointing that this doesn't seem to work anymore. Please help!
     
  3. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    Update - scene bundles built from the same project do work, it's scenes built from other projects that won't load. Which would defeat the whole purpose of asset bundles.
     
  4. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    326
    Hmm, we don't have any code restrictions specifically preventing this. So assuming the 2 projects have similar code & settings, it should load just fine. If they are not loading, then it is possible it's a configuration or missing type error in the second project. I'd suggest double checking the following:
    1. Ensure Player Setting, Graphics Settings, and Build Settings are identical on both projects
    2. Ensure that any code types you are using in the scene are located in the same assembly / path as they are on the first project.
    3. Use WebExtract & Binary2Text (located in <Unity_Install_Path>/Data/Tools) on your built asset bundles and look at the generated content to see if anything stands out.
     
  5. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    Thanks Ryanc, I'll check again, it is tricky to get everything moved forward and sync'd.
     
  6. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    So I've retested this a few times, and get the same result. @ryanc-unity (or any Unity person), can you guys confirm you've actually tested loading non-trivial scenes built from an external projects? I think the settings are correct - as noted above, I've been doing this successfully for years, across multiple platforms, until the coming of 2017x and the Asset Bundle Manager. From where I sit this is major regression. No resolution yet on the bug report above, other than to repeat that "it should be possible". I know it should be possible, but can you please confirm that it is actually possible in practice, not just in theory?
     
  7. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    326
    You pinged the wrong Ryan =P
    Looking at the Player logs submitted with the bug report, there are a lot of errors related to unable to find object or script information. So that leads me to think it's code related, so that makes me think it is related to the issue reported in https://forum.unity3d.com/threads/asset-bundles-problem-with-scripts-since-5-6-2.482908/

    If you give me a bit, I'll try and check your example before and after the fix for that issue and see if it's related.
     
  8. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    Oops, sorry! And thanks for your attention.
     
  9. polytropoi

    polytropoi

    Joined:
    Aug 16, 2006
    Posts:
    681
    I found, happily, what I think is a working solution to this, without using the AssetBundleManager package:

    Code (CSharp):
    1. UnityEngine.Networking.UnityWebRequest request = UnityEngine.Networking.UnityWebRequest.GetAssetBundle(bundleUrl, 1, 0);
    2.                     DownloadHandlerAssetBundle handler = new DownloadHandlerAssetBundle(bundleUrl, 1, 0);
    3.                     request.downloadHandler = handler;
    4.                     yield return request.Send();
    5.                     AssetBundle bundle = handler.assetBundle;
    6.                     string[] scenePath = bundle.GetAllScenePaths();
    7.                     AsyncOperation async = SceneManager.LoadSceneAsync (scenePath[0], LoadSceneMode.Additive);
    8.                     yield return async;
    9.                     bundle.Unload (false);
    Still testing, but this lets me load asset bundle scenes built from external projects; I hope that helps somebody. The bug above still stands, I think, regarding the AssetBundleManager, but that seems more oriented to build-everything-from-the-same-project scenarios anyway. Thanks to all who worked on this!
     
    Qasim337 likes this.
  10. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    326
    Hey polytropoi,
    I meant to post Friday that I was able to load your scenes directly, but based on your above reply, it would seem we now know the issue. In 2017.1, the WWW class was changed to be a wrapper around UnityWebRequest, and it would seem that the wrapper implementation has a bug in it somewhere. We'll take a look at WWW and see if we can find and fix the issue.
     
  11. orkungo

    orkungo

    Joined:
    May 3, 2014
    Posts:
    62
    Hi, is there any news for the bug? I have been loading scene from AssetBundle without any issues however suddenly it started to not to load if I dont include scene (bundled one) at the build settings on Unity Unity 2017.1.0f3.. Application quits itself whenever I want to load a scene from AssetBundle.. Do you have any ideas?
     
    Last edited: Dec 19, 2017
  12. orkungo

    orkungo

    Joined:
    May 3, 2014
    Posts:
    62
    Tested again and it seems that there is an unreliability. As I download the scene from FTP server, that was bundled from the same project, now I can open the scene as before.. however, today I got a problem for a while that when I was trying to open the scene, the application quit without any reason, no errors neither any exception.. How come it can be? All this happened at the same version (Unity 2017.1.0f3).

    Edit: Now I disabled the Stripe Code feature at the Player settings and it is working.. But it was enabled before and all worked fine until today, why does it happen?
     
    Last edited: Dec 19, 2017
  13. Ryanc_unity

    Ryanc_unity

    Unity Technologies

    Joined:
    Jul 22, 2015
    Posts:
    326
    That sounds like the engine was stripping out code that you need because it did not see that you are using it in an asset bundle. To use code stripping with asset bundles, you will need to build the player directly using a script so you can pass in a custom BuildPlayerOptions struct that points to where you built your asset bundles: https://docs.unity3d.com/ScriptReference/BuildPlayerOptions.html
     
  14. orkungo

    orkungo

    Joined:
    May 3, 2014
    Posts:
    62
    If I understood correctly, then my future bundles (that would be downloaded from FTP server) will not be included inside the BuildPlayerOptions.

    I plan to release the game with download manager, at the first run players will be automatically downloading scenes from server that are not at the build options. Then at the next phases, whenever I want to release a new level map (a new scene) I will bundle and upload it to the server (bundled from the same project and code will be exactly same as it was released so no new code or changes), then players will download them as mini updates.

    Now with BuildPlayerOptions, I will not be able to add my future bundles since it compiles. Am I correct?
     
    Last edited: Dec 21, 2017
  15. grimjim

    grimjim

    Joined:
    Jan 18, 2014
    Posts:
    15
    is there a way to use BuildPlayerOptions in cloud build ?
     
  16. carlosfarinhas

    carlosfarinhas

    Joined:
    Apr 12, 2016
    Posts:
    10
    .

    Thank you very much. Your solution worked for me. However I've got another problem.
    First time I hit a button, it loads a scene Asset Bundle from a server fine. Then I hit back to home screen. When I try to hit the button a second time, it gives me an error : "scenex.unity3d can´t be loaded because another asset bundlewith same file already loaded"
     
  17. orkungo

    orkungo

    Joined:
    May 3, 2014
    Posts:
    62
    You need to Unload the bundle with bundle.Unload(false) function after you are done with the Assetbundle. Furthermore, when you want to download a new version from server in the future, you will need to clean the cache since the previous bundle version is cached in memory so it will load the correct version you downloaded..
     
    Last edited: Jan 12, 2018
unityunity