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

How to include assetBundle into already compiled program.

Discussion in 'Scripting' started by Username_01, Aug 19, 2015.

  1. Username_01

    Username_01

    Joined:
    Aug 17, 2015
    Posts:
    13
    Related link:


    Let's say my current game's folder/file structure (very simplified) is:
    and the files that I have in downloaded assetBundle (again, very simplified) is:
    But I explained it too far. Here's much simpler version:

    How to extract assetBundle into root directory (the virtual Asset folder) permanently so that user doesn't need to be connected to internet and still be able to use DLCs. If folder's don't exist, create them, if file's don't exist, create them with proper content, if file does exist, replace it.

    I just need to extract it into root directory. And fuse them together.
     
  2. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    You can't load source through assetBundles as there would be no way for your application to compile the code, also WWW.LoadFromCacheOrDownload should work offline if the assetBundle has already been downloaded.
     
    Username_01 likes this.
  3. Username_01

    Username_01

    Joined:
    Aug 17, 2015
    Posts:
    13
    ?, and how would it work exactly?

    Code (CSharp):
    1. WWW www = WWW.LoadFromCacheOrDownload(url, 1);
    Is the code mentioned, the function itself says "Load From Cache first, then Download if possible". So it goes, to the url provided, and downloads to package. The variable makes sense.

    Now in situation when there's no internet? How would it work exactly? Will it do it automatically, le abracadabra from heavens behind the screen and magically make it work? Otherwise, where would I retrieve the package of data? Is there a command or (from PHP), that I don't know yet?
     
    Last edited: Aug 19, 2015
  4. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    Username_01 likes this.
  5. Username_01

    Username_01

    Joined:
    Aug 17, 2015
    Posts:
    13
    The manual you linked (or rather couple sections further):
    Code (CSharp):
    1.  
    2. // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
    3. using(WWW www = WWW.LoadFromCacheOrDownload (BundleURL, version)){
    4.  
    and then quotation further:
    Okay, so now, I have answer on how it works, it does load from cache magically when offline. Now I would like to know how to intentionally drop the cache, is it?:
    Code (CSharp):
    1. bundle.Unload(false);
    Also, how would it "accidentally" drop asset? When I quit application? When user deletes all cache/cookies/temp-files on his/her computer? Is there something that would drop the package and would require redownload? The begin of the page:
    Where's the so called "Cache" folder. I can't recall having such folder when having Unity game compiled.

    and it takes a lot of pre-planning
    Answering question on how to properly use scripts, requires big pre-planning?
     
    Last edited: Aug 20, 2015
  6. image28

    image28

    Joined:
    Jul 17, 2013
    Posts:
    457
    The user would have to manually clear the cache on there device or you could release a new version of the bundle and it would be re-downloaded. I'm not sure where the cache folders are, I think on Android and IOS the user can clear the application settings in there system settings menu.

    You quoted me out of context, managing assetbundles in large game projects can take a lot of pre-planning. The system I'm developing allows assetbundles for almost every part of the game. Achievements, In-App purchases, Ships, Characters, parts, pickups, menu items, etc..... Also designed it so the bundles keep downloading while the user plays the game ( so they don't have to wait ) and when it completes all the objects are loaded correctly when the appropriate scene is loaded.
     
    Last edited: Aug 20, 2015
    Username_01 likes this.
  7. Username_01

    Username_01

    Joined:
    Aug 17, 2015
    Posts:
    13
    Thanks :)

    The video I linked in first post, this dude has the file programmed to operate exclusively with objects MetalOrbs and House, he can't modify them anymore. How would you deal with such situation? I don't know what the future DLCs will contain (I have general idea, but no concrete names) so hardcoding it would be a really bad idea ("I'm so stupid!! This isn't supposed to be a cat, but tiger, now I will have to put cat image under tiger object!!", and then I will confuse in-game cat with bundled tiger).

    How would you deal with situation where objects need to be managed after downloading, without knowing their names at time of compilation? Could I include script in bundle and execute it by void() or class from "downloadDLC.cs" to the script included in bundle or something like this?
     
  8. Korno

    Korno

    Joined:
    Oct 26, 2014
    Posts:
    518
    You cant include source in an asset bundle afaik. Although on desktop, you might be able to force a compile of the new code.

    That wont work on ios or android though.