Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Bundle Manager[Released]

Discussion in 'Assets and Asset Store' started by YinXiaozhou, Jan 8, 2014.

  1. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Sorry, we don't support this. But there's still a way to cache the initial bundle by change the DownloadManager's initial process.
     
  2. argc_argv

    argc_argv

    Joined:
    Dec 14, 2013
    Posts:
    35
    Would you elaborate a little bit? Maybe I will try to customize DownloadManager's behaviour. Should I make changes to DownloadManager's inital process for example if(internet){check update}else{load cache}. Since I think download is already cache by download manager. Maybe an extension to the DownloadManger class would be a good way to go.

    But I think being able to load from cache if there is no internet is important. There are many situations where people uses the app with ipad being connected to wifi. And Unity sort of allows that with its native LoadFromCacheOrDownload.

    I think it would be a great feature for Bundle Manager to have.
     
  3. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    When developing BundleManager we focus on online games, which don't need off line cache.
    But you are right, this feature is great for those single play games. I'll consider adding this feature to BundleManager, if there's no limitation from Unity native APIs.

    The idea is to use LoadFromCacheOrDownload to download the initial bundle instead of new WWW(This part code is in Start method of Download Manager). But we need increase the version number every time to force download new version of initial bundle. If download new version of the bundle failed, then use the old version number to get the cached one.

    If you can wait. I'll try to implement this feature in two weeks. I'll send you the test version if it works. Or you can try to do it on your own.
     
  4. argc_argv

    argc_argv

    Joined:
    Dec 14, 2013
    Posts:
    35
    Having official implementation by you would be super awesome! Please send me a test version when you are ready. In the mean while I will see if I can extend the DownloadManager class and make it usable for prototyping with my app.

    Thanks so much for the amazing support!
     
  5. dbred

    dbred

    Joined:
    Oct 12, 2013
    Posts:
    3
    I have several files that have the same filename but different paths. Is there a way to load by path?
     
  6. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    No you can't. If you have same name asset in one bundle, you can only get one of them. This is how asset bundle work.
    Unless your assets is in different types, so you can get them by specify the type when using Assetbundle.Load.
     
  7. argc_argv

    argc_argv

    Joined:
    Dec 14, 2013
    Posts:
    35
    Another question:

    Do I need to unload the bundle myself? Or is it handled by bundle manager?

    Thanks!
     
  8. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Yes, you should upload it by yourself.
     
  9. argc_argv

    argc_argv

    Joined:
    Dec 14, 2013
    Posts:
    35
    thanks!

    Is the offline mode going to be available soon?
     
  10. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Still working on this. Plz, be patient:)
    We also make games beside this plugin!
     
  11. argc_argv

    argc_argv

    Joined:
    Dec 14, 2013
    Posts:
    35
    :p keep us updated!
     
  12. CnDeveloper

    CnDeveloper

    Joined:
    Jun 30, 2014
    Posts:
    1
    I use your "Download..."example, and rebuild your assets base on your "TestDownloadManage.cs" of comment, but run
    TestDownload scene have some Error like this:.. . the config txt I already replace..... 222.png
     
  13. Mt1427

    Mt1427

    Joined:
    Aug 20, 2014
    Posts:
    1
    Android not Work
    Unity:4.3.4of1
    Project:TestDownloadManager
    Log:BMData Not Failed
     
  14. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Hi, sorry for the late reply. Is the problem solved?
    Seems there's nothing in your bundle list from your log.
    Can you seed me the BundleData.txt under BundleManager folder?
     
  15. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    BTW, You can send the file to support@baxegames.com
     
  16. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Did you tried the test on your phone?
    If you want to load the bundles for your local filesystem on phones, you need to create a StreamingAssets folder in your project, And setup the Download urls for different platform.
    Please check out this for the details:
    http://docs.unity3d.com/Manual/StreamingAssets.html

    If you only test it in Editor by switching to Android platform. Can you tell me your android output url and download url in the settings panel.
     
  17. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Hi, can you contact by the email support@baxegames.com. So I can send you the test version.
     
  18. argc_argv

    argc_argv

    Joined:
    Dec 14, 2013
    Posts:
    35
    Email sent. Thanks!
     
  19. argc_argv

    argc_argv

    Joined:
    Dec 14, 2013
    Posts:
    35
    Hi, I see that 1.1.6 is released on the asset store.

    I have one problem so far and I have been able to replicate this bug:
    I am using iOS with bundle manager, the problem is like this:

    I tested by downloading the asset first from the server, with internet connection. Close the app.
    Then I turn off wifi. After that I open the app, now the bundle manager nows that it should load from cache so it does.
    Here is the catch. If I leave the app running and turn off the iPad so it goes to sleep. A few minutes later I wake the ipad with the app still running. I terminate the app. Then with wifi still turned off, I launch the app again. This time, bundle manager will not load from cache. Because it is saying that there is no internet connection and BMData file cannot be downloaded. Here is a screen shot of XCode's debugging log:



    My Bundle Manager settings:
     
    Last edited: Sep 16, 2014
  20. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Thank you for the investigation. I will check this issue.
     
  21. argc_argv

    argc_argv

    Joined:
    Dec 14, 2013
    Posts:
    35
    One other unrelated question to the previous bug.

    Does the Bundle Manager compress a texture to the correct size automatically?

    For example I have a texture that is 2048 in size, but in the game I am only using a size of 1024. When building the bundle, does the bundle manager change the property of the texture to compress it to 1024 and then bundle it?

    For reference, I am talking about this feature:
    An example of how to change the properties of the assets when building an Asset Bundle

    http://docs.unity3d.com/Manual/BuildingAssetBundles.html
     
  22. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    If you want different size on different platform. You can use the texture override feature. upload_2014-9-17_13-55-45.png
     
  23. RifS

    RifS

    Joined:
    Nov 27, 2013
    Posts:
    33
    I got "Download BMData failed" as well here.
    Already tried running on my iPad2 and still give the same error. And yes, I've built the AssetBundle with iOS format.

    I tried running running this function (via GUI Button )
    Code (csharp):
    1.     string[] assetBundleSet = new string[] {"AB-A"};
    2.     public GUIText sceneProgressText;
    3.  
    4.     IEnumerator DownloadAsset()
    5.     {
    6.         foreach(string assetBundleName in assetBundleSet)
    7.             DownloadManager.Instance.StartDownload(assetBundleName + ".assetBundle");
    8.  
    9.         bool downloadComplete = true;
    10.         do
    11.         {
    12.             downloadComplete = true;
    13.             foreach(string assetBundle in assetBundleSet)
    14.             {
    15.                 if(DownloadManager.Instance.GetWWW(assetBundle + ".assetBundle") == null)
    16.                     downloadComplete = false;
    17.             }
    18.          
    19.             List<string> sceneBundles = new List<string>();
    20.             foreach(string sceneBundleName in assetBundleSet)
    21.                 sceneBundles.Add(sceneBundleName + ".assetBundle");
    22.             float progressOfScenes = DownloadManager.Instance.ProgressOfBundles(sceneBundles.ToArray());
    23.             //Debug.Log("scenes' Progress " + progressOfScenes);
    24.             sceneProgressText.text = "scenes' Progress : " + (progressOfScenes*100).ToString("F2");
    25.          
    26.             yield return null;
    27.         }while(!downloadComplete);
    28.     }
    29.  
     
  24. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Hi Rifs,
    If you get problem on using BundleManager on IOS or Android. Plz follow steps below:

    1.Make sure your download url setting for target platform is correct. Better test it in the editor first.
    2.If you try to load bundles from local file system. Please use StreamingAssets Folder.

    If still have problem. plz contact me and send me a minimal project which can reproduce the issue.
    Thanks.
     
  25. RifS

    RifS

    Joined:
    Nov 27, 2013
    Posts:
    33
    Thank you for the prompt reply.

    I've "fixed" the problem myself. The problem was the server gave 404 when the device trying to download the BMData file.
    Since the assetBundle folder is placed in Windows Azure (Microsoft Windows Server 2013), I can't access the file with no extension. Hence I change the string of bmDataUrl from "BMData" to "BMData.bm" and create a new MIME type on Windows Server for .bm files to have application/octet-stream.

    Now I can download fine. and procedurally create the worker model with
    Code (csharp):
    1. GameObject go = DownloadManager.Instance.GetWWW("AB-A.assetBundle").assetBundle.Load("worker") as GameObject;
    2. Instantiate(go);
    But my next problem is, the second time I launch the application, I can't simply create the worker model (i.e. the assetBundle is no longer there)

    So do I need to call that "DownloadAsset" function whenever my app started?
    By doing so, The assetBundle didn't get loaded to memory right?
     
  26. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Yes. Every time you need to download your bundle. This is how streaming works...
    If you want to load your model without download, you'd better use Resource Folder or something else.
     
  27. argc_argv

    argc_argv

    Joined:
    Dec 14, 2013
    Posts:
    35
    Ok, thanks! So Bundle Manager will build bundle for that platform with the override texture size, not the default texture size?
     
  28. argc_argv

    argc_argv

    Joined:
    Dec 14, 2013
    Posts:
    35
    Another question: after loading the assetbundle and instantiating the gameobject inside the bundle. I want to unload the bundle for now. So I use bundle.Unload(false); But this does not seems to work. Because in the profiler, the memory usage does not decrease.

    But if I try to use the bundle again, then there is a error says that the bundle is null reference. But i was using the same code as the first time I downloaded the bundle and loaded the assets.

    My code:
    Code (CSharp):
    1.     IEnumerator LoadRoom(string _modelName) {
    2.         yield return StartCoroutine(DownloadManager.Instance.WaitDownload(
    3.             _modelName + StringReference.bundleExtension));
    4.  
    5.         WWW www = DownloadManager.Instance.GetWWW(_modelName + StringReference.bundleExtension);
    6.         AssetBundle bundle = www.assetBundle;
    7.  
    8.         AssetBundleRequest request = bundle.LoadAsync(_modelName, typeof(GameObject));
    9.         yield return request;
    10.  
    11.         if(currentRoom){
    12.             Destroy(currentRoom);
    13.         }
    14.         currentRoom = Instantiate(request.asset) as GameObject;
    15.         currentRoom.transform.position = transform.position;
    16.         currentRoom.transform.parent = transform;
    17.         bundle.Unload(false);
    18.     }
    With this code, the first time, I can load my asset(currentRoom). Then I try to load another asset(another room to replace currentRoom). That works as well. But if I try to load my first room, then I get this error:

    NullReferenceException: Object reference not set to an instance of an object
    RemoteAsset+<LoadRoom>c__Iterator26.MoveNext () (at Assets/Scripts/ServerConnection/RemoteAsset.cs:43)
     
  29. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Yes.
     
  30. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    The error is because the second time you try access a unloaded Asset Bundle.
    DownloadManager won't download a some WWW twice, even the you called the WaitDownload. So the second time you are trying to load from the previous bundle.
    To get a new bundle instance, you need to use DownloadManager.DisposeWWW first. Then the second time you call the method, DownloadManager will download a new bundle for you.

    For the memory, it's a little tricky here.
    Assetbundle.Unload(false) will only unload the assets which not referenced in your game. In this case, the prefab of this model will be released. But the mesh and the texture will not be released by Unload(false).
    Because when you use Instantiate(request.asset), Unity does not generate a copy of mesh and texture, Unity only keep a reference to the original mesh and textures.
    But in most case the mesh and textures cost most memory in your game. So you will not notice the memory change, but you can find the GameObject count decreased in your profiler.

    So how can we release the textures and meshes? AssetBundle.Unload(true) is a choice. But in your case, you don't want this way, since you still want to use them after this method exit.
    Another way is Resources.UnloadUnusedAssets(). When the currentRoom is destroyed, the textures and meshes of it are no longer referenced, but Unity will still keep the textures and meshes in the memory. You can use this method to release all the unreferenced assets, include the textures and meshes. Or you can leave them alone, Unity will clear unreferenced assets automatically when you try to load a new level.
     
  31. RifS

    RifS

    Joined:
    Nov 27, 2013
    Posts:
    33
    So I can include a scene with lots of prefabs in my build and have the prefabs placed somewhere not in Resource folder to reduce the application build size.?

    Another question :
    If I run the scene in UnityEditor and do the DownloadAsset() function, where is the downloaded assets saved in?
    I tried looking at Application.streamingAssetsPath, Application.persistentDataPath, Application.temporaryCachePath, and Application.dataPath, but I couldn't find any files in these folders.
     
  32. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
  33. RifS

    RifS

    Joined:
    Nov 27, 2013
    Posts:
    33
    Is there a way to rename the BMData generated when building the assetBundle to have some kind extension?
    I want to avoid renaming the BMData file to have .bm extension when my assets are built.
     
  34. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Search string "BMData" with the quotas in the project, you will find the places need modified.
     
  35. Subhajit-Nath

    Subhajit-Nath

    Joined:
    Dec 9, 2012
    Posts:
    31
    We are planning to get Bundle Manager but we aren't sure if it is proper for our scenario (as we haven't used unity's bundle system before).

    Platform: Android / iOS
    We have around 150 levels.
    We are planning to publish 50 levels initially that the player will be able to play.
    At first run, rest of the 100 levels will be downloaded and installed in the background without any user input.
    After the download is complete, player will be able to play all the levels.

    Will this all be possible without too much effort with Bundle Manager? If so then please let us know the workflow for our requirement and we will be happy to buy your product.

    Thanks in advance.
     
  36. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    This is common feature for some level based games. And you can achieve this with BundleManager easily.
    Add the first 50 levels into Unity build list. And build the rest levels into bundles.
    So player can play first 50 levels as soon as game setup. Then you can start download request for the rest levels.

    Just be careful when player isn't in wifi environment they may not want auto download. You may need to ask permission to start download.
     
  37. Subhajit-Nath

    Subhajit-Nath

    Joined:
    Dec 9, 2012
    Posts:
    31
    Glad to inform you that we bought your plugin and it's super helpful.

    We were able to build a test bundle for android but we are having some issues.

    1. Created a scene bundle.
    2. Dragged all the scene files required for bundle (it automatically added the dependency files).
    3. Changed the Download URl to http://*our host*.../Android
    4. Selected the scene-bundle and <build selection>.
    5. Uploaded the Android folder to host.

    Call the coroutine for downloading and loading a level.

    Code (CSharp):
    1. yield return StartCoroutine (DownloadManager.Instance.WaitDownload ("Themes.assetBundle"));
    2. WWW www = DownloadManager.Instance.GetWWW ("Themes.assetBundle");
    3. AssetBundle themes = www.assetBundle;
    4. themes.LoadAll ();
    5. Application.LoadLevel ("New Island2_05");
    But the problem is that we get the following errors >>>

    Download BMData failed.
    Invalid Unity Web File (Decompression Failure). URL: http://*our host*.../Android/BMData

    No matter how many times we rebuild the bundle and upload, we get the same error.

    What are we doing wrong? Please help...
     
  38. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Seems your BMData bundle is damaged? Did you tried it in editor and download from local drive?
    If you still get this error on local drive. Please create new project and make a minimal demo to test it.
     
  39. Subhajit-Nath

    Subhajit-Nath

    Joined:
    Dec 9, 2012
    Posts:
    31
    Yes, you are right, the file size doesn't match before and after upload. BMData is getting corrupted as soon as it is uploaded. But it is not corrupted if I put any extension to the file (BMData.bm) and then upload it. I am unable to upload the BMData file without extension.
     
  40. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    If you want to add extension for BMData. You can change the code to achieve that. Please check conversation in this thread between RifS and me. And I'm considering add default extension for BMData in official version too.
     
  41. Subhajit-Nath

    Subhajit-Nath

    Joined:
    Dec 9, 2012
    Posts:
    31
    Thanks for the reply. There is one other question that arises from RifS' and your conversation.
    Will downloadmanger download all the levels each and every time the game runs? Won't it cache the levels so that we don't need to download every time? just like WWW.LoadFromCacheOrDownload ()?

    Another question:
    Is there any way to get the download percentage (for displaying through progress bar)?

    Thanks for all the help so far.
     
  42. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    DownloadManager will cache every bundle if you turned on the cache option.

    You can get the download progress by DownloadManager.ProgressOfBundles
     
  43. ronjart

    ronjart

    Joined:
    May 16, 2013
    Posts:
    100
    I'm looking for an asset bundle solution and the asset store has led me here. Looks promising! My main concern is how your asset is going to work with unity 5 and the new asset bundle system. Will it be compatible out of the box and will it take advantage of the new features?

    Thank you for your time.
     
  44. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    All my knowledge of Bundle System in Unity 5 comes from this video. Seems the APIs we currently using can also work in Unity 5, which is great.

    Although the new bundle system have some advantages compare to our plugin, but as I can see there's some design problem in it. For example, new bundle system only allow one asset per bundle, this is bad for many kind of game. They don't have a bundle list like us. People still need to write code for build system and take care about bundle targets.

    The 'real' increment build by hash is good(In our plugin we compare the change time of files, working great). And the new runtime API of cache download can avoid some problems in old system.
    We are going to take these advantages from new bundle system, if the APIs is open enough.
     
  45. ronjart

    ronjart

    Joined:
    May 16, 2013
    Posts:
    100
    I was concerned when I read the bullet-point highlighted in red at about 9 minuted into the video noting: "Don't mix old/new build system". This kind of prompted my question in the first place. I guess that note only relates to the build system and not full asset bundle system.

    It is good to hear that you guys are still evolving the product and judging by your quick response, you are on top of things. Thanks!

    Also: Unity's CTO gives some insight about the subject in this thread. A little over my head, but it might be of use to you.
     
  46. AlienMe

    AlienMe

    Joined:
    Sep 16, 2014
    Posts:
    93
    Hi YinXiaozhou,

    I am having an issue when adding Sprites to a bundle. I have a Test.PNG, with its texture type set to Sprite.

    If I create a bundle using BundleManager with this sprite in it, the resulting bundle has a single object in it, of type Texture2D. Bundle Manager is also ignoring Sprite Packer's Atlases.

    On the other hand, if I create a bundle using the sample code found here: http://docs.unity3d.com/ScriptReference/BuildPipeline.BuildAssetBundle.html, selecting the same sprite, then the resulting bundle contains 2 objects, both named Test.PNG, a Texture2D and a Sprite.

    For testing, I changed Bundle Manager's BuildHelper.cs, around line 294, from this:

    Code (CSharp):
    1. UnityEngine.Object asset = AssetDatabase.LoadAssetAtPath(assetPath, typeof(UnityEngine.Object));
    2. if (asset)
    3.     assets.Add( asset )
    to this:


    Code (CSharp):
    1. UnityEngine.Object[] subAssets = AssetDatabase.LoadAllAssetsAtPath( assetPath );
    2. if( subAssets != null && subAssets.Length > 0 )
    3. {
    4.       foreach (var iter in subAssets)
    5.       {
    6.            assets.Add( iter );
    7.       }
    8. }
    9.  
    And this seems to add both the Texture2D and the Sprite (with the proper Sprite Packer's Atlas).

    Is the above change good? Does it do what I expect it to do (have a bundle with Sprites and Atlases inside).
     
  47. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    I think your solution is better than the original code. I will add it to Bundle Manager. Thanks.
     
  48. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    The warning worries me too. I hope Unity can also keep evolving the old system, so the old API can benefit from the features. Thank you for the reference.
     
  49. argc_argv

    argc_argv

    Joined:
    Dec 14, 2013
    Posts:
    35
    Hey there,

    Is 1.1.7 released? I can't see it on the store, it's waiting for approval?

    Thanks!
     
  50. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Sorry, It's a mistake.
    1.1.7 is still waiting for approval by AssetStore. It will be released in a few days.