Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    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
    You can use offline cache to achieve most features you need.
    By offline cache enabled, Download will load the cached BM.data when device is offline. When game is online, Download manager can download from your server to get the newest BM.data and update changed bundles.

    But it dose not supporting load from prepackaged bundles in the first time. To make sure bundles are cached, the game need to online at first time to download everything.
    Although, there's still a way that you can modify the source code of DownloadManager to achieve that, by force redirecting the download target to local path when device is offline and there's no BM.data cached.
     
  2. BoYing

    BoYing

    Joined:
    Aug 20, 2015
    Posts:
    1
    I've build three assetbundles , one is a cube and another is sphere , and the third is a share pack of a shader,cube and sphere use it , a shader of unlit written by myself

    Question 1: When I load them in runtime , the cube cannot Instantiate with no errorlog...
    Question 2: The sphere is load successfully , but it lost the shader , I really don't know why... when i clear and rebuildAll the shader can be found for sphere,but the shader not work...
    Question 3: When I try to use the priority set the sharebundle 9 ,cube 1 ,sphere 1, it doesn't written to the BundleData.txt , and after a few minites the priority all will be 0 ...

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class TestBM : MonoBehaviour
    5. {
    6.     AssetBundle _ab;
    7.  
    8.     // Use this for initialization
    9.     IEnumerator Start()
    10.     {
    11.         while (!DownloadManager.Instance.ConfigLoaded)
    12.             yield return null;
    13.  
    14.         yield return StartCoroutine(DownloadManager.Instance.WaitDownload("CubeBundle.assetBundle"));
    15.         WWW www = DownloadManager.Instance.GetWWW("CubeBundle.assetBundle");
    16.         Instantiate(www.assetBundle.Load("sscube"), Vector3.one * 5, Quaternion.identity);
    17.  
    18.         yield return StartCoroutine(DownloadManager.Instance.WaitDownload("SphereBundle.assetBundle"));
    19.         WWW www1 = DownloadManager.Instance.GetWWW("SphereBundle.assetBundle");
    20.         Instantiate(www1.assetBundle.Load("sphere"), Vector3.one * 0, Quaternion.identity);
    21.     }
    22. }
    23.  
     
  3. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Hi everyone, 1.2.1 is available now, with webGL and a few enhancement.
     
  4. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    After launch for over a year and a half, we decide to reduce the price to 25$.
    And now we have a trial version for you to try our product before purchase.

    Thank you for supporting our product. We will keep maintaining it. Any feedback is welcome.
     
  5. ProfPivec

    ProfPivec

    Joined:
    Sep 21, 2012
    Posts:
    28
    I am using Unity Pro 4.6.8 with SmartFoxServer 2.10.

    Smart fox uses Json for WebGL implementation and hence when I try to import Bundle Manager, I get the following error:

    Assets/BundleManager/Src/Editor/Core/BMDataAccessor.cs(113,26): error CS0433: The imported type `LitJson.JsonMapper' is defined multiple times

    Any constructive ideas how I can fix this with Bundle manager? I could run an older version of the Smartfox API but then I cannot use WebGL.
     
  6. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Hi ProfPivec, I just send you a email.
     
  7. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @YinXiaozhou
    I left my project for a very long time and am now just picking it back up again and am having a problem I can't seem to figure out. Hoping you can help me =)

    I upgraded the project to Unity 5.2 and updated to the latest version of Bundle Manager.
    I'm using the following code to load my asset bundle but end up with the www object not holding any reference to an asset bundle:
    Code (CSharp):
    1. // You should only use the file name to access your bundle but not the full url.
    2.         yield return StartCoroutine(DownloadManager.Instance.WaitDownload(dynamicBundleName));
    3.         WWW www = DownloadManager.Instance.GetWWW(dynamicBundleName);
    4.         var bundle = www.assetBundle;
    5.         GameObject newStoryObject = Instantiate(bundle.LoadAsset<GameObject>(dynamicAssetName), storySpawnPos, Quaternion.identity) as GameObject;
    The asset bundle name is exactly the same as what the WWW object was looking for:


    I've deleted old asset bundles and created new ones that are indeed in the folder that it is looking in.... here is a screenshot of my www object.



    Any idea why I'm failing to get an assetBundle in my WWW object?

    Thanks
     
  8. Lazy

    Lazy

    Joined:
    Oct 5, 2012
    Posts:
    7
    Any error message? I cant find anything wrong with this code, it's so simple. From the debuger the WWW seems failed on this task. Could be some environment setting issue. My suggestion is write a simple demo with hardcoding bundle name. If still have problem, send me the demo.
     
  9. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @Lazy
    Just the error message of a null reference exception because I'm trying to access www.assetBundle which is null. I'll try using a hard string just to ensure its the correct name and see what happens.

    Update: No difference with a hard string. Its weird as well because the Test scene works for all test cases except I get an error about it not being about to load the LE asset bundle.
     
    Last edited: Oct 21, 2015
  10. Lazy

    Lazy

    Joined:
    Oct 5, 2012
    Posts:
    7
    So can you send your test to me?
    The error about test case scene is alright, because LE is empty in that test.
     
  11. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    Ok, so I figured out the issue, but don't really understand why its an issue. Looks like last time I was working on this many months ago, I added some code to "unload" the bundle. I must have read something somewhere that it is smart to unload the bundle whenever you don't use it? Anyways, my game is set up where an asset bundle is first downloaded when the player selects some DLC (and I show a progress bar), then I was doing the code:
    yieldreturnnull; // I guess you need to wait a frame before unloading?
    bundle.Unload(false);

    Then, I had a seperate method to actually load the content into the game, which was getting null for assetBundle when the above unload code is executed, but it works fine if I don't run that code....

    So the question is.... should I or should I not be unloading bundles? I know nothing about the best practices in regards to this. Why doesn't my assetBundle load back up again if I run that unload code from a previous time that I loaded it?
     
  12. Lazy

    Lazy

    Joined:
    Oct 5, 2012
    Posts:
    7
    After unload the assetBundle instance in WWW will be null. So you need to redownload the bundle.
    Try code like below.
    Code (CSharp):
    1. public class TestDownloadManager : MonoBehaviour
    2. {
    3.     IEnumerator Start()
    4.     {
    5.         yield return StartCoroutine( DownloadManager.Instance.WaitDownload("ACA.assetBundle") );
    6.         Instantiate(DownloadManager.Instance.GetWWW("ACA.assetBundle").assetBundle.LoadAsset<UnityEngine.Object>("Cube"));
    7.         DownloadManager.Instance.GetWWW("ACA.assetBundle").assetBundle.Unload(false);
    8.         DownloadManager.Instance.DisposeWWW("ACA.assetBundle");
    9.  
    10.         yield return StartCoroutine( DownloadManager.Instance.WaitDownload("ACA.assetBundle") );
    11.         Instantiate(DownloadManager.Instance.GetWWW("ACA.assetBundle").assetBundle.LoadAsset<UnityEngine.Object>("Cube"));
    12.         DownloadManager.Instance.GetWWW("ACA.assetBundle").assetBundle.Unload(false);
    13.         DownloadManager.Instance.DisposeWWW("ACA.assetBundle");
    14.     }
    15. }
     
  13. phoenixrising

    phoenixrising

    Joined:
    Aug 9, 2013
    Posts:
    57
    Hi, I am testing in the Unity Editor for IOS build and all shaders that are not standard are not loading when using the bundle manager to load the scenes such as Mobile/Diffuse

    How can I package the shaders into the bundle manager?
    Or why in the unity editor is it unable to load the shaders that are in the project?

    I have not tested this on the device yet only in unity editor

    Also, the skybox is not loading when downloading the scene with bundle manager.

    Any ideas on how I can fix this?

    Thanks!

    ps
    I love this asset, great work!
     
  14. phoenixrising

    phoenixrising

    Joined:
    Aug 9, 2013
    Posts:
    57
    I am getting some errors in the logs but they are not effecting my game.

    I was just wondering if you know the cause of them and how to fix them?

    Could not produce class with ID 184
    (Filename: /Users/builduser/buildslave/unity/build/Runtime/Serialize/PersistentManager.cpp Line: 1241)

    Could not produce class with ID 186
    (Filename: /Users/builduser/buildslave/unity/build/Runtime/Serialize/PersistentManager.cpp Line: 1241)

    I checked here http://docs.unity3d.com/Manual/ClassIDReference.html
     
  15. phoenixrising

    phoenixrising

    Joined:
    Aug 9, 2013
    Posts:
    57
    I am having trouble setting BMConfiger to use cache, for some reason it is always false and I need to hard code it to true.

    Debug.Log(ta.text);
    bmConfiger = JsonMapper.ToObject< BMConfiger >(ta.text);
    Debug.Log("hard coded usecache and use crc");
    bmConfiger.useCache=true;
    bmConfiger.useCRC=true;
     
  16. phoenixrising

    phoenixrising

    Joined:
    Aug 9, 2013
    Posts:
    57
    I have a feature request, I would like to be able to load and save the bundle manager ( i dont know what to call it) the stuff within the bundles window. Lets call it the Bundle Setup.

    That way I can setup all bundles for application A save the bundle setup, build the actual bundles.
    Then I switch to application B in the same project, clear the bundle setup, setup bundles for application B save the bundle setup and then build the actual bundles.

    Now I switch back to application A and load the application A bundle setup.
     
  17. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Sorry for no respond for such a long time. For some reason I didn't receive the forum notification for this post. But you can always find me by our support email address.

    1.For the skybox/shader issue. You need add shaders manually to Edit->Project Settings->GraphicsSettings, if your shader only included in the bundles. And it might be a bug in Unity's bundle system that shaders sometimes don't work in editor mode. But when you build it to the app(no matter desktop or on mobile), it shows again.

    2."Could not produce class with ID 184". Never see the log before, have no idea where it comes from.

    3.Do you still have the issue? I cannot reproduce this. Please give me more information if you have.

    4.BM is designed to be have only one setup in one project. I don't think have multiple BM setup in one project is a good practice. But you could do that by replacing the 3 *.txt files under BM folder when you switching between your setups.
     
  18. Ashano

    Ashano

    Joined:
    Sep 23, 2015
    Posts:
    1
    Hi,

    We just bought your package today and were able to load our bundle locally from our system. We have made an apk for android platform, Our initial scene loads but the asset from our server is not downloading. We don't know if what we have done is correct in code, or if we are even able to download(Because we waited for 30mins and nothing seems to be happening). Posting the code we are using:


    Code (CSharp):
    1. IEnumerator Start()
    2.     {
    3.  
    4.  
    5.  
    6.         foreach(string sceneBundleName in sceneList)
    7.             DownloadManager.Instance.StartDownload(sceneBundleName + ".assetBundle");
    8.  
    9.      
    10.  
    11.         sceneBundleSucceed = false;
    12.         do
    13.         {
    14.             sceneBundleSucceed = true;
    15.             foreach(string sceneBundleName in sceneList)
    16.             {
    17.                 if(DownloadManager.Instance.GetWWW(sceneBundleName + ".assetBundle") == null)
    18.                 {
    19.  
    20.                     sceneBundleSucceed = false;
    21.                 }
    22.                
    23.  
    24.             }
    25.      
    26.             List<string> sceneBundles = new List<string>();
    27.             foreach(string sceneBundleName in sceneList)
    28.                 sceneBundles.Add(sceneBundleName + ".assetBundle");
    29.             float progressOfScenes = DownloadManager.Instance.ProgressOfBundles(sceneBundles.ToArray());
    30.        
    31.          
    32.      
    33.             yield return null;
    34.      
    35.         }
    36. CSharp]while(!sceneBundleSucceed);
    37.  


    Thank you.
     
    Last edited: Nov 24, 2015
  19. akstntn

    akstntn

    Joined:
    May 28, 2013
    Posts:
    20
    Is it possible to download multiple asset bundles at the same time?
    I have multiple buttons to download different asset bundles.
    When I click a button to download an asset bundle and click another button before finishing download the first asset bundle, the second asset bundle is not started to download till the first asset bundle is downloaded.
     
  20. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Yes, there's Download Thread Limit in settings panel. Set it to whatever you want.
     
  21. akstntn

    akstntn

    Joined:
    May 28, 2013
    Posts:
    20
    I set it to 3 and tried to download 3 asset bundles at the same time but still each asset bundle is downloaded one by one.
     
  22. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Okay. I reproduced the same problem. But the sad thing is I found that it's a bug of Unity. You can simply create 3 WWW request and print their progress to check that.
    I don't know when they introduced this bug, but I'm sure that back in 4.5 or earlier it's definitely working. I will commit a bug report, hoping they can fix this.
     
  23. akstntn

    akstntn

    Joined:
    May 28, 2013
    Posts:
    20
    Thank you for your answer.
    How do I fix the problem to download multiple assets at the same time?
    Could you give me an example?
    Thank you!
     
  24. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Sorry, maybe my broken english confused you.
    I mean I can't download multiple bundles parallel in current version because of engine's bug.
     
  25. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @YinXiaozhou
    I have several audio files in my project that have the same names such as "storyAudio1", but I have them separated using folders. When I add all these audio files to an asset bundle it seems like it gets flattened and the folder organization is lost..... What options do I have to organize same name audio files in my asset bundle? Or do I have to give every audio file name a unique name no matter what?
     
  26. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Yes. You have to rename them to different names. Unity cannot figure out which one you want to load, if there's several assets with same name in the bundle.
     
  27. CYS

    CYS

    Joined:
    Aug 25, 2013
    Posts:
    11
    Hi! I have several questions which i hope someone can help.

    1) I notice the .cs files are also under the 'DEPEND' area of my 'Scene Bundle'. Does that mean the scripts are also packaged into the exported bundle? I doubt that's allowed according to Apple's guideline. If it's not, i suppose i can just ignore them?

    2) I'm currently using the trial version to see if it serves my purpose. May I know the limitation of it?

    3) I'm still in the process of understanding how AssetBundle works. I experimented by including my scene in a new Scene Bundle. The scenes have many references to textures (from 2D Toolkit). So with just that single 'Scene Bundle', i do a build and the file is 250+ mb!

    Now, i added the textures in the scene into a separate 'Asset Bundle'. After which, I put that 'Scene Bundle' from before as its child. I rebuild it. The total size becomes 50mb+!!!

    Can someone explain why this happen? If i'm not wrong, building the scene alone also included all those textures into the bundle. Splitting them up shouldn't actually have any effect on the total bundle file size?

    Thanks a lot!!
     
  28. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    @CYS
    1. You can just ignore that. Depend means the bundle needs there assets, but not just pack all of them into the bundle. For scripts, the bundle only contains some reference information of that script. Actually you can't pack any compiled scripts into the asset bundle even you intent to.
    2. If you mean functionality, the trial version can't change the default settings of Bundle Manager.
    3. I guess you are using Unity 5.3? This version currently broke the compress feature of legacy bundle API. It's a bug of Unity. And if you want to use asset bundle on 5.3, you'd better use Unity's new asset bundle system(It's hard to use, I know, but sorry I can't fix the bug of Unity:).
     
  29. CYS

    CYS

    Joined:
    Aug 25, 2013
    Posts:
    11
    Understood! Thanks a lot!

    And yeh, I'm indeed using Unity 5.3. I do manage to trial and error until it's reasonable size and it has worked thus far (I bought the plugin) so i'm continuing with it. Thanks again for this plugin :D.
     
  30. CYS

    CYS

    Joined:
    Aug 25, 2013
    Posts:
    11
    Hi, sorry it's me again but the bug you mentioned got me worried that I may be doing it wrong and that it will stop working the moment unity fixes the bug.

    So just to clarify - currently I have only a single scene bundle. Included in it is a single scene. Listed in the manager are many dependencies of sound clips. There are NO OTHER asset/scene bundles. I do a build all.

    When I load the scene from the generated bundle, it seems to load correctly. The music clips are also loaded (and are not from the project folder). Everything seems perfect.

    This is a strange question but is this supposed to happen? Do I need to create another asset bundle containing the sound clips and load them manually in the scene? Or are the music clips magically included in the scene bundle and loaded together with the scene.

    Thanks!
     
  31. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Yes, it's what we expected to happen. If the bundle contains the scene, it will contains all the asset needed in it. Unity can gather all the dependencies automatically.

    The bug I mentioned is in some situation, the Unity(Legacy building API) dose not compress the bundles anymore. Which makes the bundle much bigger than it should be.
     
  32. CYS

    CYS

    Joined:
    Aug 25, 2013
    Posts:
    11
    Good to hear, thanks a lot!
     
  33. Mage-Co

    Mage-Co

    Joined:
    Jul 1, 2014
    Posts:
    13
    Hi I have bought thís asset however I recognize whenever I increase version then my game download new one then the disk space increase, it mean the bundle have not replaced by new one. Please help may be I not set up correct.
     
  34. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    @Mage Co This is expected. The cache system of Unity has a algorithm to remove the cached data, but not just by replacing the old version one. It's like expired data deleting process or something. And the caching system also has size limitation. So don't worry it won't explode the hard drive.
     
  35. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    I am having what appears to be system memory issues while using Asset Bundles that is making my app crash on device, hoping someone can give some advice as I'm all out of ideas.

    In my app, I have some content that is built into the APK, and also DLC content that is downloaded via Asset Bundle. The user can toggle between the content simply by pressing a button, so I delete the currently loaded content gameobject, and then load the next content. On device, if I toggle to load the same DLC content from an asset bundle several times, the app ends up crashing, so it seems like I'm perhaps not cleaning up the asset bundle correctly and memory ends up filling up? (Its strange because in the Editor while using the Profiler it doesn't seem like the Texture Memory continually climbs)

    Here is the code I run when I toggle changing between some content to load, sometimes content from Resources, other times from Asset Bundle:

    Code (CSharp):
    1.  
    2. // This is called when the user toggle to load the next available content, current BSVolume is incremented each time
    3. public void OpenNextBSVolume()
    4.     {
    5.         currentBSVolume = gamestate.Instance.GetNextAvailableVolumeNumber(currentBSVolume, true);
    6.         StartCoroutine(LoadBSVolume());
    7.     }
    8.  
    9.     IEnumerator LoadBSVolume()
    10.     {
    11.         selectedRes = "2x";
    12.  
    13.         ShowActivityIndicator(true);
    14.  
    15.         // Remove old volume
    16.         Destroy(BSStickerPage.GetChild(0).gameObject);
    17.  
    18.         Resources.UnloadUnusedAssets();
    19.  
    20.         // DLC loads from Asset Bundles
    21.         if (currentBSVolume > 1)
    22.         {
    23.  
    24.             bundleFile = "Volume" + currentBSVolume + selectedRes + ".assetBundle";
    25.  
    26.             // Load the asset bundle
    27.             yield return StartCoroutine(DownloadManager.Instance.WaitDownload(bundleFile));
    28.  
    29.             // Load chosen volume
    30.             GameObject chosenBSVolume = Instantiate(DownloadManager.Instance.GetWWW(bundleFile).assetBundle.LoadAsset("Volume" + currentBSVolume + "BuildAScene@2x") as GameObject, Vector2.zero, Quaternion.identity) as GameObject;
    31.             chosenBSVolume.transform.parent = BSStickerPage.transform;
    32.             chosenBSVolume.transform.localPosition = new Vector3(0, 0, -1);
    33.  
    34.             DownloadManager.Instance.GetWWW(bundleFile).assetBundle.Unload(false);
    35.             DownloadManager.Instance.DisposeWWW(bundleFile);
    36.         }
    37.         else
    38.         {
    39.             // Load volume 1
    40.             GameObject chosenBSVolume = Instantiate(Resources.Load("Volume1/BuildASceneContainers/Volume1BuildAScene@2x") as GameObject, Vector2.zero, Quaternion.identity) as GameObject;
    41.             chosenBSVolume.transform.parent = BSStickerPage.transform;
    42.             chosenBSVolume.transform.localPosition = new Vector3(0, 0, -1);
    43.         }
    44.  
    45.         ShowActivityIndicator(false);
    46.     }
    Does anyone have any thoughts on what I'm doing wrong?
     
  36. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Your bundle load/unload code seems pretty neat for me. But there's a risk that when player switch the toggle too fast, there will be multiple coroutine of LoadBSVolume running at the same time, that will cause memory leak.
    Or maybe you have some routine some where else to prevent that issue?
     
  37. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    I've been testing to not toggle LoadBSVolume until the content is fully loaded.... I'm not sure what to do.... :(
     
  38. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Can you connect the unity profiler to android app? See if the memory is actually rising. And get the crash report to check if it's because of memory.
     
  39. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
  40. akstntn

    akstntn

    Joined:
    May 28, 2013
    Posts:
    20
    Is it possible to get 'download url' from sever and change the old download url to the new download url?
     
  41. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Yes. You can use BMRedirect.txt.

    Make a new file named BMRedirect.txt and put it in to the download url. When DownloadManager initialize, it will try to get BMRedirect.txt first from the download url. If there’s a BMRedirect.txt, DownloadManager’s target url will follow the url in it.
     
  42. phoenixrising

    phoenixrising

    Joined:
    Aug 9, 2013
    Posts:
    57
    I just found a bug using the caching from DownloadManager.cs for newer unity versions
    If offline www does not give error
    so I need to test for assetbundle to use cache

    if(initDataWWW.error !=null || initDataWWW.assetBundle==null)
    {
     
  43. akstntn

    akstntn

    Joined:
    May 28, 2013
    Posts:
    20
    For example, if a user plays my game which is version 1 the user needs to download files from www.bundles.version1. and, if the other users plays my game which is version 2 then the user needs to download files from www.bundles.version2. How should I set BMRedirect.txt?
    Thank you!
     
  44. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Dose you mean that in newer version of Unity the WWW.error won't contains data when it downloaded nothing?
    What's the version are you using?
     
  45. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    There's several ways for you to achieve that.
    1.Use DownloadManager.SetManualUrl to set the url manually before using any DownloadManager.Instance in your code.
    2.Before build your app, in the editor, assign different target url in setting of BundleManager.
    3.Point your download target to a local position, and put different BMRedirect.txt in it for different version of your app.
     
  46. rxmarccall

    rxmarccall

    Joined:
    Oct 13, 2011
    Posts:
    353
    @YinXiaozhou
    I'm trying to prevent memory leaks in my game and trying to make sure I clean up after I use an asset bundle, but don't seem to understand the correct way to load an asset bundle, unload it, and load it again later on.

    First I load it:
    Code (CSharp):
    1. yield return StartCoroutine(DownloadManager.Instance.WaitDownload(dynamicBundleName));
    2.         WWW www = DownloadManager.Instance.GetWWW(dynamicBundleName);
    3.         var bundle = www.assetBundle;
    Then after pulling what I need out of the asset bundle I want to unload it:
    Code (CSharp):
    1. WWW www = DownloadManager.Instance.GetWWW(dynamicBundleName);
    2.         www.assetBundle.Unload(false);
    3.         Resources.UnloadUnusedAssets();
    Then later on when I need to load the asset bundle again, I execute the first code snippet again, but I get a "Object reference not set to an instance of an object" error. Can you help me understand what I'm doing wrong here and what the correct way to load / unload an asset bundle several times as needed is?
     
  47. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Did you also get some error like " Cannot load cached AssetBundle. A file of the same name is already loaded from another AssetBundle"? It's because the bundle haven't fully released, you should use assetBundle.Unload(true) instead.
     
  48. Kamand0l

    Kamand0l

    Joined:
    May 19, 2014
    Posts:
    24
    In the recent version 5.3.4p2, Unity fixed the issue that legacy API call BuildPipeline.BuildStreamedSceneAssetBundle did not compress the bundles.

    (781866) - Editor: Fixed an issue where compression wasn't being applied in calls to BuildPipeline.BuildStreamedSceneAssetBundle()
     
  49. brianye

    brianye

    Joined:
    Jun 13, 2016
    Posts:
    2
    @YinXiaozhou

    Hi,

    I've been stuck on something. So, in the app I'm developing, have a code which, in a click of a button, checks the asset bundles I have and sees if any of them needs an update from my server. I do this by running it through the "isBundleCached" function. If there needs to be an update, I update it using startdownload (or waitdownload).

    I'm trying to implement an automatic update feature. While the game is already running, I upload a newer version of a bundle onto my server, and want the code to be able to update it. When I click the update button, the isBundleCached function tells me that the version is already cached. When I restart my game, the update button works as it should.

    I'm guessing the reason behind this is that the BMdata and buildstates file that the game obtains is downloaded when the game starts to run, and when I update a bundle on the server while the game is still running, the files become outdated? If that is the case, how can I fix this issue?

    Thanks for any help!
     
  50. YinXiaozhou

    YinXiaozhou

    Joined:
    Oct 19, 2013
    Posts:
    133
    Hi brianye,

    BM dose not support bundle update on the run. Since DownloadManager only download the bundle config data at first call to Download.Instance for once. So player need to restart the app to get the new version of bundles. Normally that won't be problem.

    But you can change the DownloadManager to manually reinit it. All the initial process is down in IEnumerator Start() method. And you need to change a little bit of the bundle download process, so that it can detect bundle's version change to redownload same bundles again even they are already loaded into memory.