Search Unity

Working Multi-Resolution Sprite Sheets

Discussion in '2D' started by TheFuntastic, Oct 18, 2014.

  1. Mike-Geig

    Mike-Geig

    Unity Technologies

    Joined:
    Aug 16, 2013
    Posts:
    254
    @Kiori - Here are some answers for you (hopefully)

    -You can use bundles along with the sprite packer atlases, but there is a specific workflow. First, even though your HD and SD sprites have the same name and general structure, they need to have two separate sprite sheets (you can't put them on the same one). Then, when building your bundles, there is an option to pack only the atlas and not the original sprite. I'm going off of the top of my head, but I believe it is "CollectDependencies". I will have to check when I get a moment (my own personal project is structured this way and I just haven't checked tro make sure the atlassing works yet).

    -This system works perfectly for all platforms. It is a simple matter of structure and I believe the demo was made for simplicity, so it only highlights one platform. Basically, you can build the bundles for all target platforms (you can even build them all at once) and then just have the device look in the correct folder using some platform defines.

    -The asset bundle name and variant drop downs in the editor work great (it's how I make bundles) and is definitely feature ready.

    -Regarding the pixels to units for SD versus HD: I have only tested my solution for UI's, but I did not have to change anything for SD and HD to work correctly (I really need to find the time to finish this project and get it out).

    Hope that helps

    Cheers.
     
  2. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    what about for re-skinning sprites?
    like is discussed @19:20 in this video
    youtu.be/rMCLWt1DuqI?t=19m20s
    is there some way that asset bundles can make swapping skins easier or more efficient then a search and replace of sprite names in lateUpdate from resources folder?
    thanks

    edit: ya thanks for the sprite packer in free version so nice and easy :)
     
    Last edited: Apr 11, 2015
    Kiori likes this.
  3. Kiori

    Kiori

    Joined:
    Jun 25, 2014
    Posts:
    161
    @Mike Geig

    Thanks Mike, as always.
    The thing about having the option to pack only the atlas is good to know.
    My point about the sprite packer is that its not really 'known' and it needs some dev attention i think.(maybe it is getting it)
    Maybe you should teach about it on the coming live training(the one about asset bundles). To me sprite packing/handling is an ultra essential part of the asset bundle scheme. Its like a missing link without it.

    Ideally I would like the sprite packer to be fully integrated into Unity, where i can just select sprites and right click, pack with sprite packer, then it goes into a gui, where i can set names, packing options, algorithms, whatever, then click ok and it generates the atlas for me. Also, as with everything Unity, I would like to have that be possible in code, at run time.
    This goes in line with what rakkarage said/asked/requested. It all has to do with how unity handles Sprites, and therefore the overall 2D workflow.

    This is ideally of course. I hope the unity devs do get around implementing something along those general lines. These are base features for 2D devs, that would actually add a lot of value to unity as a whole, and could even be used in 3d games.
    Unity has come a long way for 2D, but there is no limit going forward.

    Thanks again anyhow, whatever you do teach in the coming tutorial, I'll be eager to see it. :)
    I hope I am free during the time so i can attend it live.
     
  4. KJoanette

    KJoanette

    Joined:
    Jun 8, 2013
    Posts:
    59
    CollectDependencies is marked Obselete
     
  5. Mike-Geig

    Mike-Geig

    Unity Technologies

    Joined:
    Aug 16, 2013
    Posts:
    254
    xoxma and Stef_Morojna like this.
  6. swipeware

    swipeware

    Joined:
    Mar 24, 2015
    Posts:
    3
    @Mike Geig

    That was Awesome! I finally managed to get my SD/HD assets to load properly in my 2D game, and it works great with sprite animations as well. I'm a very happy camper!
    Your AssetManager and LoadScene scripts were exactly what I needed.

    I'm adding some extra code to LoadScene which programatically determines which variant (SD/HD) to load depending on the device resolution, and I'm setting AssetManager.instance.bundleVariants just before the call to AssetManager.instance.LoadBundle() which I assume should be the best place for it?
     
  7. Mike-Geig

    Mike-Geig

    Unity Technologies

    Joined:
    Aug 16, 2013
    Posts:
    254
    @swipeware yes that would work. Remember that you can only load 1 variant of a bundle per execution, so just be sure to load the variants you need as soon as you can. It sounds like you'll be good ot go.
     
    Stef_Morojna likes this.
  8. swipeware

    swipeware

    Joined:
    Mar 24, 2015
    Posts:
    3
    @Mike Geig
    Thanks for the info, and thanks again for the training session!
    These "new" Asset Bundles are shaping up to be really powerful...
     
  9. Kiori

    Kiori

    Joined:
    Jun 25, 2014
    Posts:
    161
    @Mike Geig thanks for the tut, i couldnt be there at the time.
    I had a question, my guess is currently the system doesnt work for wp8 and other platforms, since you said unsupported.

    Also someone asked why there isnt a gui solution and you said its because the system is too complex, yet you made a script that acts kind of like a gui solution to cover that, so clearly a gui solution is a necessity. I hope unity comes around that and implements it.

    In that context when you said unity handled dependencies i thought it would sort things out on its own, then later on the script has to manually load each dep. I guess what you mean is that unity lists the dependencies for you in the manifest, it doesn't really handle them.

    Thanks for the tutorial Mike it clear at least a few things up, I wont be using the system for now though, lack of wp8 is too big a hit for me. Also i find 2dtoolkit's solution more elegant atm, looking forward to future updates though.
     
  10. Mike-Geig

    Mike-Geig

    Unity Technologies

    Joined:
    Aug 16, 2013
    Posts:
    254
    Howdy @Kiori , I think you've made some incorrect assumptions based on the live training. I hope this clears it up.

    Nope, I didn't say that (maybe you are thinking of the video I did previously on Unity Ads?). WP8 is supported just fine. If you want it as a platform, simply add it to the build script

    Disagreed. I made a script that shows one way of potentially doing it. The fact is that there are so many different ways of doing it, that there isn't a one-size-fits-all system. That's why there is no built in UI way of handling it.

    Unity does handle dependencies, and I demonstrated that fact in the video. I was able to load a scene and Unity loaded all the dependencies of the scene without my script doing that. I also said that you are able to manually load the dependencies yourself if you want / need to, and then I demonstrated that as well with the manifest.

    Hope that helps clear some things up.
     
  11. Stef_Morojna

    Stef_Morojna

    Joined:
    Apr 15, 2015
    Posts:
    289
    I can't wait for this to be in unity.
    Then I can just make all my textures high resolution so it works great with the iPhones6 2200x1200 screen, but still works normal with older devices.
    This is the best solution for pixel perfection on 1080p devices and still being able to run on lower
    resolution.
     
  12. Kiori

    Kiori

    Joined:
    Jun 25, 2014
    Posts:
    161
    @Mike Geig
    Thanks Mike, that does clear up a -lot- of things, I understand things more clearly now. :)

    Btw, so that means every platform is currently supported right?

    Oh and yeah about the dependencies, i forgot that at first you simply loaded the scene, now i see i got confused.
    Well, good to know, i'll use what you set as reference and try to build my own script for my own simple needs and see how it goes.
    -----

    And why would you need to load the dependencies yourself? I don't really see a scenario where that would be useful.
    Actually this is something that i was thinking about at the end, why was that complicated huge script needed if the process its self is rather simple. Even if you are doing manifest checking.
    I saw the unity dev's demo also btw, its even more complex.
    ----

    Oh, also, something i forgot to ask.
    As for the path to the bundle, how do I set an "%appdata" keyword or something so that it always looks in the game folder for it?

    Veli uses' url = "file://" + Application.dataPath.Replace ("Assets", "AssetBundles/") + variant; '
    in his video.

    --TomasJ answered my question about pixeltounits--


    Thanks again for the -awesomely- fast response, i really did need the feedback today.
    I see now how asset bundles are a step forward for us.
     
    Last edited: May 11, 2015
  13. TomasJ

    TomasJ

    Joined:
    Sep 26, 2010
    Posts:
    256
    There's a misconception in this thread about what a sprite and an atlas actually are, so I'll try to explain it briefly:
    • A Sprite is an object containing a reference to one Texture and some properties, such as UnitsToPixels.
    • By default a Sprite references the Texture it is produced from.
    • When a packing tag is set, the Sprite will switch its internal Texture reference to the atlas texture on some events (entering play mode, building the player, building a bundle).
    • There is no such thing as an atlas object. There are just Sprites referencing Textures.
    • When you build a project, assets are serialized only if they are referenced. SpriteRenderer, animations and scripts can reference Sprites, which reference Textures. That is how those textures get pulled in to the final data files.
    • When you build an asset bundle, you have to ask for the Sprites to be included in it, not the Textures. That way only the correct (atlas) Texture will be pulled into the bundle. If this is done incorrectly, both the source and the atlas Texture will be pulled in.
    • If you want to use up-scaled textures in HD (i.e. 2x the size), then adjust UnitsToPixels accordingly and your final Sprite world-size will remain the same.
     
    Kiori likes this.
  14. Kiori

    Kiori

    Joined:
    Jun 25, 2014
    Posts:
    161
    Ok so im building my own solution to test and further understand things, i made a few slight changes to the original script but basically atm it is the LevelVariantLoader.cs Mike provided.

    In the tut Mike demoed selecting the folders HD and SD and tagging them as bundlename with variant hd/sd.
    However when build i get the following error:
    1.!asset.IsFolderAsset ()
    2.Unrecognized assets cannot be included in AssetBundles: "Assets/Scene 1/SD".

    It looked like it didnt want to build a folder into an asset bundle, so i selected the sprite inside and set it into bundle, and var, etc.
    Then it worked, it built the bundles yei, which moves us into problem number 2, so far.
    When the script works it gives me this error:
    Level '/scenes/scene1' (-1) couldn't be loaded because it has not been added to the build settings.

    which is kind of funny considering an asset bundle scene cant be included into the build, and thats the idea, DLCs right.

    Did I not understand something, what's going on? anyone is welcome to chip in.
     

    Attached Files:

  15. Kiori

    Kiori

    Joined:
    Jun 25, 2014
    Posts:
    161
    So i fixed the script and self-answered all my questions.

    This script works for basic solutions like mine, it accepts a scene in a bundle, and the assets of such, also in a bundle, with 2 variants one called "sd" the other called "hd", and it outputs what you would expect depending on the setup.

    The fields in the inspector are:
    Path: the path to the bundles folder inside your asset folder, whatever folder you choose when building the bundles.

    Scene Bundle Name: the name of the scene bundle, with the path to it.So it may be something like scenes/scene1. It will naturally look for it inside the bundles path.

    Scene Name: The name of the scene inside the 'scene bundle' being loaded.

    Variant: sd or hd, the variant types you have to set while building your asset bundles.

    Asset Bundle Name: the name of the bundles with the assets that the scene requires, include the path inside the bundles folder. so it may be something like assets/scene1assets

    HD_Res X and Y these values set at which resolution it will switch form sd to hd, if they are set to 0, it this part will be ignored and whatever is set in "variant" will be loaded instead.
    That way you can also manually test things.

    Don't forget to normalize the sprites with the pixelToUnits option as stated above.

    Anyone who wants to is welcome to use this script.
    Its very basic but it should get you started with bundles in your project.
    I also included the "AssetBundleMenu" script Mike Geig provided in the live tutorial, its what i used to build the scripts in the first place, and my entire script is derived from the tutorial its self.
     

    Attached Files:

    keely likes this.
  16. deemen

    deemen

    Joined:
    Dec 29, 2013
    Posts:
    17
    I'm having a ton of problems generating Asset Bundle Variants for our game. I think this system currently has a ton of drawbacks:
    1. I have been unable to generate the variant bundles due to hash collisions. According to the documentation, this is because we have too many assets in our bundle. I've tried with as little as 10 and still get a ton of collisions. It seems to collide frequently on assets with the same name (even in different folders and with a different GUID).
    2. You can't simply load a variant, you need to place your scenes in asset bundles as well. This adds a ton of extra complexity which I don't think it necessary. It also caused some of our scripts to be excluded from the build (because they are used only in 1 scene). I don't know how to force Unity to include the script while keeping that scene in a separate bundle without duplicating the scene in the main binary.
    3. Uncompressed asset bundles allow us to stream content, but if placed in the StreamingAssets folder they are uncompressed in the APK / IPA which balloons download size.
    4. Compressed asset bundles have a hefty memory penalty since the scene and the asset bundle must stay in memory until loading is complete. This is the kind of spike that kills apps with lots of content.
    What I would like to see is:
    1. I create an asset bundle variant and tag assets with the same name somewhere in my project.
    2. Unity detects that those assets belong to an asset bundle and doesn't include them in the main build (regardless of where they are in scenes or prefabs).
    3. At run time I choose an asset bundle variant and load a scene, the correct assets are chosen.
    4. I can stream from compressed asset bundles to prevent memory spikes (basically mounting and unmounting the asset bundle, many zip libraries allow this, and I would gladly lower the compression ratio to prevent the memory spike).
    Despite upgrading to Unity 5 specifically for the asset bundle variant feature, I don't feel like it is production-ready at this stage. You basically need to engineer it into your game from the start, and the added complexity of having scenes in asset bundles means that for now a workaround makes the most sense. It makes me regret using the new Unity UI and sprite animation systems, because if we had stuck with Tk2D, we wouldn't have this problem at all.

    This is also a CRITICAL feature. Unity seems to prioritize things that show off well in shiny tech demos or tutorial videos, but when it comes to actually shipping a game where you need to deal with memory / disk constraints on a console or mobile phone, it seems like an oversight. Every mobile game engine I have encountered ships with some way of scaling assets based on screen resolution. The currently suggested solutions are a massive pain in the ass for the reasons above.
     
    Kiori likes this.
  17. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    Hi deemen,

    (replying to your numbers)

    1. You should share a repro case for us. This would be interesting for the guys working in asset bundle code.
    2. Scenes ONLY have to be in bundle if you have pre-instantiated stuff (like props) that would like to use variants. If you are writing a game that does runtime instantiation, your (non-bundled) scene could load a bundled prefab that uses a variant-bundled texture. See attached examples.
    3. In the near future, everything on disk will be lz4 compressed. I'm hoping this will come ASAP since it is quite a hotly requested feature.
    4. This won't be true once #3 gets shipped. It will be on the fly.

    AssetBundle variants serves as the base for the multi-resolution feature. What it needs next is high-level tooling to make working with it easier. We hope to have this high-level stuff soon-ish.

    Agreed. We are on it.
     

    Attached Files:

  18. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    I'd like to express my frustrations as well. The simple example provided looked so promising but when I actually go to make use of asset bundles in a real project, issues keep coming up. I work around one issue and then run into another.

    Right now, I'm trying to figure out why it insists that a particular sprite asset is a dependency when it's really not. Basically, Level 1 has Sprite 1, Level 2 has Sprite 2. Each level and each sprite is in a separate asset bundle. For some reason the Level 1 asset bundle thinks that Sprite 2 is a dependency, which means it includes the entire Sprite 2 asset bundle as a dependency in the manifest. In the editor, when I highlight the Level 1 scene and select "Select Dependencies" it does indeed select Sprite 2, even though it is not in the scene. But when I actually open up the Level 1 scene, select Sprite 2 in the Project and then "Find References In Scene", it does *not* show up.

    After some tinkering on this issue, it seems that it's because I'm using prefabs and the prefab definition had Sprite 2 on it, BUT Level 1 scene is overriding that setting of the prefab with Sprite 1. So final result should be that Sprite 1 is a dependency and Sprite 2 is not. Instead, both are listed as dependencies.

    This may not be an issue with asset bundles specifically, but asset bundles are definitely affected by it.
     
    Kiori likes this.
  19. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    What happens if your prefab don't reference sprite 2? Does it bundle them cleanly?
     
  20. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    Yes. Following the example, if the prefab is defined with a sprite that is not part of any asset bundle, and then the instance of that prefab is overwritten with Sprite 1, then Sprite 2 bundle is not seen as a dependency. That's the work-around I'm going with right now but it's not ideal because then I have these extra place-holder sprites included in the project that are never seen in the actual game.


    I can provide a small repro project if you'd like.
     
    Last edited: Jun 2, 2015
  21. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    I get it now, you have to have a place holder sprite so that it could be replaced by the variant system? Yes, perhaps submit this as a bug and see what my colleagues have to say about it. And thanks for high lighting this potential workflow issue.
     
    theANMATOR2b likes this.
  22. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    Yes. Well, the variant system does replace it either way. It's just that the dependencies are resolved incorrectly. And even with the place holder they're still resolved incorrectly (it thinks the place-holder is a dependency), but at least it doesn't think it needs another asset bundle.

    Will do. Thanks for the response.
     
  23. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    When you say sprite1 and sprite2, are they really named sprite1 and sprite2? One of the key to make it work is the names and the organization (files and folders) of the 2 variant folders must be identical. What is your setup?
     
  24. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    For the HD/SD variant replacement, they are the same name. Sprite 1 is for level 1, sprite 2 is for level 2. Then there would be "sprite1.png" in the HD folder as bundle "sprite1.hd", and "sprite1.png" in the SD folder as bundle "sprite1.sd".

    I've attached the small repro project (using apples and oranges for sprites instead) to demonstrate. There is no code in there to actually load HD/SD variants. As mentioned, this appears to be a prefab bug and I wanted to isolate that but it's important that the asset bundles are still assigned.
     

    Attached Files:

  25. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    Please post a bug report. Thanks!
     
  26. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    Case 701446, submitted this morning.
     
  27. Kiori

    Kiori

    Joined:
    Jun 25, 2014
    Posts:
    161
    Last edited: Jun 6, 2015
  28. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    Looks like Vincent is has been alerted to your case.
     
    Kiori likes this.
  29. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    I still haven't received any response to the bug report (other than the automated email).

    I've run into another workflow issues though...
    We need to put our SD/HD asset variants in bundles. And we need to create separate asset bundles for each platform. There is no platform specific Resources or StreamingAssets folders (although it has been asked for http://feedback.unity3d.com/suggestions/platform-dependent-streamingassets-folders).

    How do we include only the asset bundle relevant to the platform we're building for?
     
    Kiori likes this.
  30. Deleted User

    Deleted User

    Guest

    Yes, we don't have platform dependent streaming assets folder.
    As a workaround, you can build to somewhere else with correct platform dependent subfolder, and copy the AssetBundles to streaming asset folder before building the player data according to the target platform.
     
  31. soaring

    soaring

    Joined:
    Jun 22, 2015
    Posts:
    27
    Also, I have been looking around for this information without success. In iOS, there are typically 2 different temporary directories available for downloading assets into, one is "Documents" director, the other is "Cache" directory where iOS could clean out the content without your knowleadge. Where does WWW.LoadFromCacheOrDownload download its asset?
     
    Kiori likes this.
  32. Aleksei-Laser

    Aleksei-Laser

    Joined:
    Apr 4, 2014
    Posts:
    7
    Hello
    The video is not available. There can I find it?
     
  33. JnJ_art

    JnJ_art

    Joined:
    Jun 25, 2015
    Posts:
    1
    Hi,
    Same issue as you Aleksei Laser
    Mike Geig, any idea/link ?
    Thanks.
     
  34. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    @ColossalPaul From what I've gathered so far, using CreateFromFile with compressed asset bundles might be the ticket to all of this coming together for me. I have a couple more questions though:
    1. What kind of performance can we expect from this? Are there any benchmarks versus using WWW?
    2. Can you confirm that this feature is listed on the roadmap as "Deploy: LZ4 data compression" and is expected to be included in the release of Unity 5.3 on December 8th?
    Thanks!
     
  35. User42671515

    User42671515

    Joined:
    Jul 15, 2015
    Posts:
    1
  36. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
    Hi,
    AssetBundle.CreateFromFile is the fastest way to load asset bundles atm. Data of a bundle loaded in this way is being read directly from the disk when needed. So loading is essentially parsing headers and registering bundle's objects.
    Don't think it could be compared with WWW as WWW even if used with "file://" actually loads bundle into memory and it takes both time and memory.

    Right now CreateFromFile supports only uncompressed asset bundles. In 5.3 we want to introduce ability to load compressed bundles of two types: chunk compressed lz4 which uses realtime decompression (stored in compressed form on disk, but are a bit larger than lzma compressed bundles) and standard lzma bundles which are being decompressed to the memory before use.
     
  37. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
    Cached AssetBundle files are stored in decompressed and unpacked form.
    Base directory for cached data is:
    • iOS: Library directory in user space (NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES)). Files are stored with com.apple.MobileBackup" attribute set to 0.
    • Android: If external storage available (WRITE_EXTERNAL_STORAGE is set and storage is mounted) - Environment.getExternalStorageDirectory() + "/Android/data/" + Context.getPackageName() + "/files/", if not - Context.getFilesDir().
    Plus "/UnityCache/<hash>", where <hash> is a hash of AssetBundle URL without GET params.
    Take in mind that the format of cached data and location might be changed in future and it's not recommended to manage it directly.
     
  38. Aleksei-Laser

    Aleksei-Laser

    Joined:
    Apr 4, 2014
    Posts:
    7
    Could you provide correct link to Mike's video?
     
  39. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
  40. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    Question about this. Let's say I publish an android APK without WRITE_EXTERNAL_STORAGE and the user installs it ends up with asset bundle data stored in getFilesDir(). Then I publish an update with a new APK that does have the WRITE_EXTERNAL_STORAGE permission. After the user updates the app, the asset bundle data in getFilesDir() should still be there.
    Will the new published app forget that the files are in the old location and require the user to re-download and re-cache the asset bundles without cleaning up the old files?
    Or will it move the files from the old location to the new location and use them in the new location?
    Or will it still make use of the existing data in the old cache folder?
     
    Kiori likes this.
  41. Kiori

    Kiori

    Joined:
    Jun 25, 2014
    Posts:
    161
    Ok so basically CreateFromFile is the way to go if you are distributing asset bundles with your game(and we should use the 'StreamingAssets' folder). And, in 5.3 we can expect real time decompression, creating a compromise between build size and load times, correct?

    Also, following up on everyone's questions, if CreateFromFile is the way to go, but it requires uncompressed bundle in the streamingAsets folder that means that if you are downloading from the web the only way is to use WWW.LoadFromCacheOrDownload, or simply www.

    But in both cases(createFromFile and WWWs) you need to call www.assetBundle, or does createFromFile autoloads everything inside the bundle?

    In fact there are so many functions around using asset bundles that what needs to go/where gets uncertain at times. In the video tut. for example when loading a scene, www was used, www.assetBundle was not used...

    I mean i made my own version of the scripts and they work great, but I'd be lying if i said i fully understood what each class does internally what are the requirements, and therefore how to optimize around it. To me asset bundles are still a land of uncertainty and doubt.

    Furthermore I often times find myself experimenting with unity in order to really understand things that the docs/videos haven't made clear at all, in depth i mean. You guys need to find people who are really clean and go deep in their explanations to get in touch with the community.
    All the tutors i've seen so far are only good at teaching absolute beginners how to do beginners' stuff and keep the script kids happy, most of the tutorials are not explaining what things truly are, how and where, we only rarely get that from blog posts, which are much appreciated btw.
     
  42. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
    Yes, exactly. When asset bundles are shipped within a game in 'StreamingAssets' folder, AssetBundle.CreateFromFile should be used. In 5.3 we want to introduce additional compression type (LZ4) which is a tradeoff between ultimate compression (LZMA) and fast load (uncompressed). Right now, LZ4 compressed bundles are 0.4-0.6 of original size without sacrificing loading performance.

    Yes, for now the only API that can download from the web are WWW.LoadFromCacheOrDownload and WWW.
    Besides that 5.2 will introduce Networking: WebRequest (experimental) (desktops and webgl first) which will be a replacement for WWW once implemented on all platforms and provides streaming functionality so that annoying `double asset bundle data` problem will disappear.

    CreateFromFile returns ready to use asset bundle.

    We are updating documentation on that and want to provide High Level API to simplify loading bundles, managing dependencies etc. (see attached demo project at http://forum.unity3d.com/threads/new-assetbundle-build-system-in-unity-5-0.293975/).
    Also take a look at How do I cache AssetBundles? section in the docs.

    AssetBundle loading pipeline still needs ironing and we are working on how to make it more convenient, faster and have no unnecessary memory footprints.
     
    Kiori likes this.
  43. alexeyzakharov

    alexeyzakharov

    Joined:
    Jul 2, 2014
    Posts:
    507
    I think this is the scenario we have right now. Bundles we'll be redownloaded.
     
  44. mdrotar

    mdrotar

    Joined:
    Aug 26, 2013
    Posts:
    377
    The more worrying part about this is that the old asset bundles will remain on the device. The user will end up with 2 copies of the same asset bundles. When a user is running low on space, they go their apps list and sort by space usage to start deleting apps. An android game made with Unity in this scenario will very likely end up at the top of that list. That's bad for business.

    Is there a reliable way to avoid this situation?
     
  45. Ovenden

    Ovenden

    Joined:
    Jul 17, 2015
    Posts:
    1
    As someone new investigating Unity as a replacement for Corona, this is super important. In Corona I simply place my base resolution and my @2x, @3x, etc in the same folder and the correct image is automatically selected.

    I know we are currently waiting on some kind of update with some way to handle this but it all seems a lot more complicated than Corona. Right now I'm wondering if it really makes sense for me to move as I only ever intend to do 2D development, and this functionality missing/requiring work to implement seems like a deal breaker for me.

    For a system that sells itself on being a GUI editor, this is pretty basic functionality required for mobile development that seems to need a lot of coding to fix.
     
    Last edited: Jul 18, 2015
  46. WiedemannD

    WiedemannD

    Joined:
    Mar 4, 2015
    Posts:
    19
    This post seems to be the most comprehensive documentation on how to handle multi-res sprites with asset bundles and it is definitely better than not having it, though I'm still a bit lost.

    Our iOS app is hard on the limit of memory usage so we need to find a way to exchange low-res/high-res sprites depending on the current device, which is what this post seems to be about. First I tried my luck with using mipmaps to achieve this kind of automatically, but image quality was so bad, we had to kick that. Now my best guess is on using asset bundles as is mostly talked about here. But I'm looking for an efficient way to use Unity's Sprite Packer and the new AssetBundle workflow, at best with bundle variants, so I wouldn't need to "manually" exchange sprites myself like Veli Pekka Kokkonen did in his presentation (if that's not possible it would be the least problem though).

    My problem with Veli Pekka Kokkonen's and ColossalPaul's solution is that sprite packing is not directly involved (Unity's internal one not any third party solution), which seems to me quite a big issue. And I gotta admit I'm a bit surprised, that this topic does not seem to be regarded as huge as I think it should be (if it is, sorry for my assumption).

    Anyway, from my understanding there are at least two issues with the combination of using the Sprite Packer and Asset Bundles with variants:

    1) As far as I understood, for bundle variants to work, assets need to be named identically in the different bundles. How can I achieve this when using two SD and HD atlases, which would need to be named differently via the packing tag? So SD and HD sprites wouldn't end up in the same atlas, which would make the whole thing senseless.

    I somewhere read about "atlas variants" as well (sry can't find that post anymore), but my guess is there is no real comparable implementation like with asset bundles yet, right?

    2) Currently in Unity 5.1.2 I can only set an asset bundle name and variant name per texture, but not per sprite. So from what I understood the original texture AND the atlas (because of the referenced sprites and their dependencies to the atlas) would be part of the asset bundle. As mentioned here before having both the atlas AND the original textures in the asset bundle, would make the whole thing useless again, as memory consumption would bloat again.

    The following issue comments say, that this was somehow solved. Can someone else confirm this?
    https://bitbucket.org/Unity-Technologies/2ddemos/issues/3/asset-bundles-should-work-with-sprite

    Other than that, I came upon the more "manual" version of BuildAssetBundles(...):
    Code (CSharp):
    1. public static AssetBundleManifest BuildAssetBundles(string outputPath, AssetBundleBuild[] builds, BuildAssetBundleOptions assetBundleOptions = BuildAssetBundleOptions.None, BuildTarget targetPlatform = BuildTarget.WebPlayer);
    http://docs.unity3d.com/ScriptReference/BuildPipeline.BuildAssetBundles.html

    If I understand correctly it describes the use of AssetBundleBuild[] builds to specify which objects should be bundled instead of using the editor dropdowns. Maybe it's possible through this to just add the sprites and their atlases to an asset bundle instead of additionally adding the original texture? Has someone experience with this? It would probably be the next thing for me to test. And for a full solution I would need to create some custom script to exchange the sprites in a scene, which sadly would make asset bundle variants useless as far as I can see, or am I wrong?

    Features that would really be handy:
    - Real variants for sprite atlases as well, similar to asset bundles. So the two systems would be really compatible to each other.
    - The possibility to only add subassets like sprites etc to an asset bundle without their parents. Maybe for you Unity guys it's just making the corresponding dropdowns visible for those?

    Other than that, I was looking for the live training session by @Mike Geig on asset bundles and couldn't find it. Does someone know where it is available?

    I'm very thankful for an help whatsoever!

    Cheers

    EDIT:
    Damn ... it seems I might just have missed the last some posts. I'll check again today and if needed delete this post.

    EDIT 2:
    Well after reading the second page of comments, most of my questions still stand. So any help is very much appreciated!
     
    Last edited: Jul 20, 2015
  47. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    First thing first, we have big plans to upgrade the sprite packing workflow. Stay tuned! Admittedly, the sprite packing and bundling process seems opaque (as in you don't really know what goes in where). We are working on making that more visible.

    This can be done by setting a different tag for each variant. So all the sprites in the SD variant folder should have Packing Tag like Atlas_SD and the HD sprites would have Atlas_HD. This will ensure they don't end up in the same atlas which then allows the AssetBundle to bundle them separately.

    This has been fixed. Coming out in 5.2.

    No promises, but the new sprite packer workflow lends itself elegantly to this. Stay tuned!
     
  48. ColossalPaul

    ColossalPaul

    Unity Technologies

    Joined:
    May 1, 2013
    Posts:
    174
    Of course I'm biased but I would think yes.

    There is no fixing with code required here. We have an atlasing system that works with bundling variants. See my previous post.

    About corona, if you really just want to load between @2x or @3x then perhaps corona is 'less lines of code'. However, in most real situations, developers want, runtime download of compressed asset packs (asset bundles), with automated runtime re-linking, and highly optimized atlases. And not only textures, but prefabs, shaders, animations, meshes. So if you try to all these in corona, you might find more code needs to be written.

    (If corona somehow supports all these built-in, I take back my words).

    All the stuff we talked about here works (with one pending bug where the texture AND atlas was bundled together. Fixed for 5.2). The massive amount of confusion seems to come from the fact that both bundling and sprite packing (and their synergy) was initially designed to 'just work' with zero intervention. However, due to the immensely wide variety of 'preferences' and different needs of different projects, we are now working on giving you more manual control so you can actually see/feel/touch how these things are atlased and bundled.

    Hope this helps nudge you along (to our warm embrace) :)
     
  49. WiedemannD

    WiedemannD

    Joined:
    Mar 4, 2015
    Posts:
    19
    @ColossalPaul
    Well thank you very much for the explanations. I thought naming atlases different would mess up the needed synchronicity between bundle variants, but it's good to hear that only sprite names seem to be required to be named the same, when using atlases. My guess is, if you would want to actually use textures in variants without "atlas linkage" to these, they would need to be named the same though?

    Do you think the fix for not including the original texture AND the atlas in an asset bundle might make it into one of your awesome patch releases? This would be really great, especially as it sounds it has been already fixed!

    EDIT:
    Would it still make sense to look into the more manual version of BuildPipeline.BuildAssetBundles() with the AssetBundleBuild[] build map to include just atlases and not the original sprites for example, or is this a hopeless approach?

    EDIT 2:
    Well, sadly BuildPipeline.BuildAssetBundles() with the AssetBundleBuild[] build map does only take paths to physical files through AssetBundleBuilds. I tried variations like "pathToTexture/spriteName" and "pathToTexture/textureFilename.png/spriteName", but it seems to be just not supported so far. I also checked if you could get to some subasset path scheme via the sprites' instanceIDs and GUIDs to get a path via AssetDatabase's methods, but they simply returned the path to the texture main asset.

    I also found this http://answers.unity3d.com/questions/993571/create-an-asset-bundle-from-sprite-packer-texture.html , which seems to be a rather nasty workaround for the current issue in 5.1.2 with adding the atlas and the original textures to an asset bundle.
     
    Last edited: Jul 21, 2015
  50. WiedemannD

    WiedemannD

    Joined:
    Mar 4, 2015
    Posts:
    19
    Bildschirmfoto 2015-07-21 um 17.15.00.png

    Just a simple EditorWindow for configuring and starting the asset bundles build process. Originally I wanted to extend this heavily to add just sprites and their atlases instead of their original textures, but see my post above. If someone wants to extend my script please do so. (I commented out some of my internally used editor GUI functions, to make it a bit more "pretty", same goes for the more manual version of building bundles with a build map).
     

    Attached Files:

    theANMATOR2b likes this.