Search Unity

Question about Asset Bundle version.

Discussion in 'Editor & General Support' started by zyndro, Mar 28, 2012.

  1. zyndro

    zyndro

    Joined:
    Oct 19, 2010
    Posts:
    78
    Hello there guys.


    i have a question, i've been reading and looking for all the site and web and still dont get it..

    its about setting up versions of my assets bundles, so i can deliver new content to my app and will be updated automatically.

    i know i can use WWW.LoadFromCacheOrDownload (url : String, version : int) where the integer "version" will be de latest version to download.

    My question is, where do i should specify the version of the asset when im building the asset bundle?

    or im wrong?


    i suposse this works as follows..

    - you create an asset bundle and specify " this is version 3 " for example..
    - app connects to the server and check, "whats this build's version?"
    - asset bundle is marked as 3, so the app by using the www.loadfromcacheordownload says.. mmm..i have the 2 version, ok ill download this.."
    - app download the new version.

    is this the workflow? or im totally lost?

    can someone explain me whats the workflow? i know www.loadfromcacheordownload will download the latest according to the integer in www.loadfromcacheordownload(url : String, version : int) but, how do i insert the version in the asset build when i build it ?


    Thank you so much!

    Best regards,
     
    GubaLord likes this.
  2. samix

    samix

    Joined:
    Mar 21, 2012
    Posts:
    3
    You are not alone. I'm confused too.
     
  3. diablo

    diablo

    Joined:
    Jan 3, 2011
    Posts:
    736
    You don't assign a version number when building, only when loading. So whenever you loadfromcache, you are assigning that asset a version number, and the very first time, it loads that asset into the cache. The next time you loadfromcache, if the version number you supply is the same, it will retrieve the asset from cache. If the version is different, it will load it into cache again.
     
  4. elhispano

    elhispano

    Joined:
    Jan 23, 2012
    Posts:
    52
    Thanks you!
     
  5. clooper

    clooper

    Joined:
    Jul 22, 2013
    Posts:
    6
    It doesn't work. I have an executable, generating a brand new cache key each time it is run. But instead of therefore downloading a brand new assetbundle it insists on using the one it has previously cached. I've checked the logs and the cache key is indeed different each time.

    To get the executable to download a new assetbundle I have to rebuild the executable.
     
  6. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,288
    Post some code so we can see what you are doing. What do you mean by the cache key?
     
  7. lilboylost

    lilboylost

    Joined:
    Feb 12, 2014
    Posts:
    265
    If I update the bundle on server. Unity will still load from cache, correct?
     
  8. Graham-Dunnett

    Graham-Dunnett

    Unity Technologies

    Joined:
    Jun 2, 2009
    Posts:
    4,288
    Yes, unless you use the version argument.
     
  9. lilboylost

    lilboylost

    Joined:
    Feb 12, 2014
    Posts:
    265
    How do I pass in the version number when I create Asset from Memory?

    Use-case:
    AssetBundle OrigBundle -> Encrypt -> TextAsset -> Packed into AssetBundle say PublicBundle

    My game downloads the public bundle , Read the text asset, decrypt the bytes and create original bundle using AssetBundle.CreateFromMemoryImmediate.

    Let's say publicbundle has version 1 and game has already cached publicbundle v1 locally.

    Now I update the public bundle to v2.

    User starts the game. It loads v1 from cache and create OrigBundle. Game figures that public bundle have been update, so it downloads v2 now. Game try to recreate origBundle, but Unity gives an error that AssetBundle cannot be created because of conflict. How do I tell Unity that this assetbundle is v2 and not v1? My game do handle updating asset smoothly.
     
  10. slw825

    slw825

    Joined:
    Mar 23, 2013
    Posts:
    10
    Hey, I'm dealing with some issue about this, too.

    My problem is I could use all the assetbundle feature well, but what if I want user to comfirm it such as clicking checking box before begining download the latest bundles.
    Is there any way to do it without using a server to achive this method?

    Thx :)
     
  11. jnthn_

    jnthn_

    Joined:
    Apr 12, 2015
    Posts:
    1
    Hi everyone, I have a similar problema with AssetBundle in Unity 4.6.

    The file AssetBundle (ExampleAssetBundle.unity3d) change periodically, I need charge the "last versión" every time.

    The application needs to work offline, for that, I use LoadFromCacheOrDownload but always loads the first version, don't know how to especify that always download the latest version.

    I'm very confused with the use of AssetBundle, help me please. Thanks!

    Here is a example code:


    Code (CSharp):
    1. public class ChargeAssetBundle : MonoBehaviour
    2. {
    3.         void Start ()
    4.         {
    5.                 StartCoroutine (LoadAssetBundle ());
    6.         }
    7.  
    8.         IEnumerator LoadAssetBundle ()
    9.         {    
    10.                 WWW www = WWW.LoadFromCacheOrDownload ("http://www.exampleweb.com/ExampleAssetBundle.unity3d", 1);
    11.  
    12.                 yield return www;
    13.  
    14.                 if (www.error != null) {
    15.                         yield break;
    16.                 }
    17.      
    18.                 AssetBundle bundle = www.assetBundle;
    19.      
    20.                 GameObject ExampleAssetBundle = bundle.Load ("ExampleAssetBundle", typeof(GameObject)) as GameObject;
    21.      
    22.                 GameObject newItem = Instantiate (ExampleAssetBundle) as GameObject;
    23.                 newItem.transform.SetParent (GameObject.Find ("Canvas").transform, false);
    24.      
    25.                 www.assetBundle.Unload (false);        
    26.         }
    27. }
     
  12. slw825

    slw825

    Joined:
    Mar 23, 2013
    Posts:
    10

    Well...with few months of studying, I think I had finally understood almost every features of assetbundles.... :D

    Your problem, I think, is all about the "version" you're trying to download or load the bundle which is the second parameter of LoadFromCacheOrDownload function.

    Note that unity assetbundle feature will NOT check out if it's different between the elder and the latest bundles. Actually there ISN't even a version data contains in bundle. The way assetbundle version works is determined by the "version" param. Every time you are trying to download bundles you need to tell the function which version is the proper one. If the version is higher than the current one, it will start to download new bundles through the path. If not, it will load them from cache. You might notice that it's all about the value of the version. Yeah, it means that no matter if you upload the newer bundles or not it will re-download them again if the version is higher than previous one.

    So, what you gonna do is to make sure to bring the latest version for the LoadFromCacheOrDownload function to download the proper bundles.

    Here is an quick example:
    Code (CSharp):
    1.  
    2. IEnumerator LoadAssetBundle (string _ID, int _version)
    3. {
    4.     string BaseURL = "http://www.exampleweb.com/";
    5.  
    6.     if(!_ID.Contains(".assetbundle"))
    7.         _ID += ".assetbundle";
    8.  
    9.     WWW www = WWW.LoadFromCacheOrDownload(BaseURL + _ID, _version);
    10.    
    11.     yield return www;
    12.    
    13.     if(www.error != null)
    14.         yield break;
    15.  
    16.     /// - Take the bundle ...
    17. }
    18.  
    Then call the downloader like this:
    Code (CSharp):
    1.  
    2.  
    3. public ver = ?;
    4.  
    5. void CallDownloader()
    6. {
    7.     StartCoroutine(LoadAssetBundle("ExampleAssetBundle", ver));
    8. }
    9.  
     
  13. vexe

    vexe

    Joined:
    May 18, 2013
    Posts:
    642
    What seems to be missing in all of these posts, is that if the point of asset bundles it to let you dynamically add content into the game without having to push patches and stuff, well then how do you increment the version number of the function when you upload a new version of the bundle?

    I assume you have a file in your server somewhere that has the version number in it, so you first download that number and feed it to LoadFromCacheOrDownload(url, version). Am I correct?
     
  14. VamshiKrishnaP

    VamshiKrishnaP

    Joined:
    Jan 17, 2013
    Posts:
    16
    Hi, We have used Assetbundles concept in one of my project. That project was built with Unity4.6.3.

    Now client wants some updates/changes and we are going to upgrade the project to Unity5.3.0. Those Asset bundles which we created using Unity 4.6.3 are unable to use with Unity 5.3.0.

    We are going to create new asset bundles with new version of unity.

    Is there any solution to use Assetbundles for all the Unity vesrions ?
     
  15. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    2,900
     
  16. Iseebees

    Iseebees

    Joined:
    Jan 4, 2015
    Posts:
    5
    That's the solution I chose. I created a text file called myVersion.txt. That file only contains the version number. I arbitrarily started with a version number of 10 to make sure I had a fresh download.

    In the script I use to load asset bundles, before calling Initialize() to start the Asset Bundle Manager, I first call StartCoroutine(GetVersionNumber()) to set my variable "version" to the latest version number.

    Then, I use that "version" variable when downloading bundles.
    When uploading new bundles, I also have to upload an updated myVersion.txt file that contains a higher number.

    Code (CSharp):
    1.  
    2.  
    3. private int version;
    4. private string versionNumberURL = "https://www.website.com/AssetBundles/myVersion.txt";
    5.  
    6.     public IEnumerator GetVersionNumber(){
    7.  
    8.  
    9.         using(WWW www = new WWW(versionNumberURL)) {
    10.  
    11.  
    12.             yield return www;
    13.  
    14.             if(www.error != null){
    15.  
    16.                 Debug.Log("...........................................................www has an error " + www.error.ToString());
    17.                 yield break;
    18.  
    19.             }else{
    20.  
    21.                 Debug.Log("Found ......................................................................... ==>"+ www.text +"<==");
    22.  
    23.                 int parsedVersion = int.Parse (www.text);
    24.                 version = parsedVersion;
    25.             }
    26.         }
    27.     }
    28.  
    29. // Voila!
    30.  
     
    Last edited: Feb 29, 2016
    guneyozsan likes this.
  17. tomekkie2

    tomekkie2

    Joined:
    Jul 6, 2012
    Posts:
    506
    How do you create this file?
    Why not to read the manifest file prior to downloading the assetbundle, extract crc number from the manifest file text and use that as version number? I guess crc changes during asset rebuilt.
     
unityunity