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

Unity 5 Asset Bundle System Issues / Feedback

Discussion in 'Editor & General Support' started by BFS-Kyle, May 20, 2015.

  1. BFS-Kyle

    BFS-Kyle

    Joined:
    Jun 12, 2013
    Posts:
    883
    Hey - we have recently ported over all of our games to Unity 5, and I have been working on setting up Asset Bundles for the new system too. So far I have had much worse results than the old Asset Bundle system in 4.x which was working great for us.

    ---------------------------------------------------------------------------

    Firstly, the old 4.x Asset Bundle system has been deprecated in 5.x, which is forcing us to move over to the new system. We can still use the old 4.x code for now, but it doesn't work like it used to - a bunch of functionality has been ripped out / disabled to work more in line with the 5.x asset bundle system. The main issue here was the old system of Push / Pop Asset Dependencies. This worked great for us - we always knew the order that scenes / bundles would be loaded, and could reduce the file size significantly by pushing the dependency chain. This code is still usable in 5.x, but it does nothing.

    Now this can be done in 5.x asset bundles as well - but you have to do it manually. Lets take a quick example:

    I have two scenes - GameSceneLevel1 and GameSceneLevel2. If I put them into two separate asset bundles, then they will both hold all of the assets they need. Lets say there is one big NGUI Atlas texture which takes up 5MB - both asset bundles will store the exact same texture. In 4.x, I could push the asset dependencies so that ALL the assets in GameSceneLevel1 will be shared with GameSceneLevel2 when they are loaded in that order, which means that same texture would only be stored in the first asset bundle, and only referenced in the second bundle, saving 5MB. With 5.x, in order to have the same result I need to create a third asset bundle which stores just a single asset - that texture - and the 5.x system will automatically setup the dependencies for the asset bundles. This is all OK, but where it gets tricky is when you have more than a single asset that is shared between the two scenes. What if your scene has 200 different meshes, with 200 different textures, and a bunch of sounds and other things all over the place. This now has to be handled manually, and I have to look up every single asset that might be shared and put it into the extra asset bundle. Then any time I change the scene, I need to update the shared asset bundle again - if some items are removed from the scene, they could stay in that shared asset bundle, adding some bloated size with unused assets. Basically it takes away the power of the old system automatically finding dependencies and pushes it to the user to manually handle dependencies.

    I can see why this change was made - the system in 4.x was not user-friendly and required a code setup, but we have put the effort in to create a huge asset bundle creating framework which can do everything for us so we could use the strengths of asset bundles. But the new 5.x system has been made as user-friendly as possible to accommodate a wider audience, but has removed a lot of the power that the old system gave to advanced users. In our case, its a big step backwards.



    Another issue I have found is that it seems the size of asset bundles has increased by about 10-25% between 4.x and 5.x. This, combined with the above issue of dependencies, makes the total download size for one of our games go from 263.1MB of asset bundles in 4.x, up to 350.7MB of asset bundles in 5.x. This is an increase of about 33% - I will have to go through the game and create all the shared asset bundles as described above to bring it back down, but I don't think it will ever get as low as it used to be.



    The final feedback point would be that there is no way to setup asset bundle dependencies with the base game build either. In our game, we have one really huge NGUI Atlas which takes up 10+MB of space, and we want to keep the game as small as possible. This Atlas is used in many scenes, and we want to have some of those scenes in the base game package, and other scenes downloaded from asset bundles. Currently, there is no way to tell the asset bundles to NOT include that texture because the base game will have it included. Our work-around for this is to have the base-game only include one scene called "AssetBundleLoadingScene", and 100% of the game is packaged into asset bundles. This way we can setup the dependencies and keep the size low. We then have to include the first few asset bundles in StreamingAssets or Resources to have them as part of the base game package. This is a strange way to have to set it up, but the only solution that I could find.



    ---------------------------------------------------------------------------


    Now for the bugs I have found.

    The first bug is related to materials / shaders not being linked properly in asset bundles, and showing up all pink. Someone else reported this here and I have submitted a bug report for it 697764 - but it becomes difficult to work with asset bundles when all your materials are turning pink. It appears it might be a Mac-only bug, but I haven't tested it on all systems.

    The next bug which is one of the major issues is with asset bundles with multiple scenes in them. Whenever I create an asset bundle that has two or more scenes, only one of those scenes will work. The other will lose ALL scripts on its objects, and throw a bunch of errors about unable to load resources. It has also been reported at bug 697764 (used the same bug report for both as it has our entire project as a repro case). As a result of this, I have had to split every single scene into its own asset bundle (which again makes things a big pain with shared assets, because I have to handle even more overlapping assets because of this).

    The last bug, which is less significant, is that any sound files that are added to an asset bundle do not show up in the total file size report sent to the editor log. I have been using this to try to optimise asset bundle sizes (because we need to do that manually now that we dont have push asset dependencies) and the audio always shows up as about 0.2KB, even if the actual size is a few MB. This has been reported at bug 697668.



    ---------------------------------------------------------------------------


    I like that Unity have worked on Asset Bundles to make them more user-friendly in 5.x, but unfortunately for us and likely anyone who was using asset bundles previously, it has been a step backwards in file sizes, and in time spent setting up the bundles. Hopefully the Asset Bundles will continue to be worked on so they can get back to the state they were in 4.x and then improve beyond that.
     
  2. bigbazwa

    bigbazwa

    Joined:
    Jun 18, 2013
    Posts:
    8
    I would also love to find some solution to this issue in particular. Seems like being able to have dependencies that are included in the base game is something that should be there. I've had no luck finding any information about how do that, or if its even possible though.
     
  3. Deleted User

    Deleted User

    Guest

    Actually, even we deprecate some APIs for the old build system in 5.0, the old build system should still work like before, including the Push/PopAssetDependencies.

    Do you have the details how it didn't work for you?

    Yes, we noticed that it's a problem for the customers. So we have the plan to automatically build the multi-referenced asset into other AssetBundles, it's on our to-do list.

    I heard this from our customers as well, will have a look to see what causes the increase.

    Yes, that's true, we're also looking at how we can integrate the building of player and AssetBundle.

    The fix is on the way to patch release.



    Definitely, we also need this kind of great feedback to make it better. Thanks.

     
    BFS-Kyle likes this.
  4. ricardo_arango

    ricardo_arango

    Unity Technologies

    Joined:
    Jun 18, 2009
    Posts:
    64
    With regards to the issues with multiple scenes in a bundle, that's how it has always worked. In Unity 4 you can only have one scene in an asset bundle.

    It is possible to calculate the common assets between a group of scenes automatically with a bit of code. Try the project attached in this link:

    https://oc.unity3d.com/public.php?service=files&t=a6864c6525f9293992a3a43f22a3dab5

    Given an array of objects, it can find the common assets between them. To use it go to "Test"->"Group Assets" in the menu. This is a modified version of Vincent's AssetBundle example, I made some changes to make it work in the StreamingAssets folder. What's most important in your use case is the Editor code to find the common assets and build the bundles.
     
    BFS-Kyle likes this.
  5. BFS-Kyle

    BFS-Kyle

    Joined:
    Jun 12, 2013
    Posts:
    883
    Thanks for the replies :)

    With the push/pop asset dependencies, I will check it in more detail and look at the logs too, but when I built my asset bundles in Unity 5 but using the old 4.x system with push/pop, some of the asset bundles ended up being 3-4x bigger than they should have been, and it looked exactly like the asset dependencies were not being copied over. I'll have to test it again to make sure of it, but not sure if its worth reporting it as a bug since its deprecated right?

    Hmm... maybe it was never intended to have multiple scenes in a single asset bundle even back in Unity 4, but I have definitely done it in a few games and had it working fine previously. If it is intended behaviour to limit it to just one scene per asset bundle then maybe it should show an error when trying to build them?

    Thanks for that sample - that is a much better idea than what I used (I built the asset bundles, then parsed the text in the output log file for the assets, stripped away the extra text and checked for matching file paths... but this way seems much simpler! :))
     
  6. Deleted User

    Deleted User

    Guest

    Please report a bug, it would be better if you have a simple reproducible project. Then we can see if it's a fix that we can make into the patch release.

     
  7. diekeure

    diekeure

    Joined:
    Jan 25, 2013
    Posts:
    221
    I cannot understand that someone at Unity would say that it is not possible to have multiple scenes in one asset bundle, how would you explain the existence of this page in your docs:

    http://docs.unity3d.com/ScriptReference/BuildPipeline.BuildStreamedSceneAssetBundle.html

    The first parameter is a list of scenes to include in the bundle. Please don't tell me that this doesn't work anymore!
    I have used this method for years, so I'm pretty sure it works in 4.x
     
  8. diekeure

    diekeure

    Joined:
    Jan 25, 2013
    Posts:
    221
    Or is there a difference between an assetbundle and a streamedsceneassetbundle?
     
  9. cjmanca

    cjmanca

    Joined:
    Dec 6, 2013
    Posts:
    10
    While assetbundles are being addressed, could some work be put in on multi-project assetbundles?

    In the project I'm working on, we have a single project for all the core logic and gameplay code, and then other projects with specific "sections" of the game. The main game project would then read in these bundles from the other projects when the game is played. This means that different people on the project wouldn't have access to resources they don't need access to (a level designer doesn't need combat mechanic code, for instance), and also keeps file sizes down when sharing their work with others on the team, since you just need to send the assetbundle created by your own project, rather than all the source files.

    The problem here is that there are a few assets which should be shared between these projects/bundles, but I haven't found a way to flag these as a shared resource between multiple projects so that they would only go into a single assetbundle.

    If this is something that's already incorporated, I'd love to hear how to do it, otherwise please consider it when reworking the assetbundle system.



    One other example regarding this (which I'm sure many can relate to) is modding. The ability to give others a project with "stub" scripts which they can modify and export an assetbundle from, which leverages the resources of the main game (can read from the game's included assetbundles), and then create a new asset bundle which doesn't include any of those assets from the main game. The game could then read in this assetbundle as a new mod.
     
    Last edited: Sep 14, 2015
  10. Bradamante

    Bradamante

    Joined:
    Sep 27, 2012
    Posts:
    300
    In terms of feedback ... I like the new AssetBundle system introduced in v5, but it seems to fall a bit short. Instead of tagging the assets it would be better to have a build list. Vincent acknowledged this in his Unite presentation, so I am hoping.

    As far as problems and bugs ...

    I just started implementing modding in my project, by loading AssetBundles from a folder in Application.persistentDataPath. The very same code that works in the Editor does not work in a build (v5.2.0f3, Mac OS X). The build freezes/beachballs when loading the first bundle. It's not a path issue.

    Another thing I found is a bug(?) where the AssetBundle builder (Unity v5+) does not cleanly resolve dependencies when the scripts are missing. Here's how that works:

    Let's say you have a prefab with a script that has a public Transform[]. You could use this to set up dependencies on other objects. Now transfer these prefabs to a different project via a package export. In the new project, import the package but not the script with the public Transform[]. As expected, the script will show up as Missing in the prefab. Delete the script from the prefab. Now you can compile and continue working.

    In the AssetBundle build however, the dependecy still shows up in the .manifest. This issue is no big deal since it doesn't stop my workflow from working but it shows that either the AssetBundle build code or Unity's serialization has issues. Who would have thought ;)

    I guess I will file bugs tomorrow. The latter one is easy to reproduce.

    I am pretty sure you are asking too much here. When it comes to asset differences and additive vs. exclusive loading ... well, you have to manage that yourself. In my case the asset bundle includes a config file that tells the game if to load the assets exclusively or additively. You could also do this on a asset by asset basis by using an ID system where a modded asset with the same ID replaces a built-in asset with that ID.

    A modder reading from asset bundles included in a game should be near impossible. That would only work with mod creation tools built into the game (which I would not want). But you can load asset bundles from an external source.

    A bigger issue is that basically any modder has to go through Unity to create mods, as long as you can only load asset bundles (instead of loading sounds, particles, pictures, 3D models directly). You can parse a 3D model as a text file in a build, but what if you want to mod particle systems or sounds? I guess the only thing you can do is to make creating a mod for your game inside Unity as easy as possible, using a good instruction PDF, an example mod setup and a lof of conveniance scripts.

     
    Last edited: Sep 19, 2015
  11. jonlab

    jonlab

    Joined:
    Apr 6, 2010
    Posts:
    182
    Sorry to bump this post, ...
    Any progress on the "materials turn to pink (or not behaving correctly) when loaded from an Asset Bundle" issue ?
    This is really a blocking bug for modular content projects, when you can not have all your content in the same Unity project.
    And this is still there in Unity 5.3.1...
    My post about that : http://forum.unity3d.com/threads/assetbundles-and-dependencies.377760/
     
  12. memetic-arts

    memetic-arts

    Joined:
    Feb 27, 2011
    Posts:
    82
    Another bump from me. Also using 5.3.1 (p4), on OSX, building to iOS, and am using the AssetBundle Manager system that Vincent and team have built (though for scene loading only -- had to bail on it for individual assets). I have been able to successfully load a single scene, but all of my attempts to load a subsequent scene result in either missing or mis-applied materials.

    I was having the pink-shader problem like everyone else also, but found a fix for that, by setting up the shaders in Project Settings>Graphics. Now when everything goes pink, it's because the entire material is not set to the prefab-instantiation that was in the pre-bundled scene.

    Really could use some assistance here, as the ability to switch scenes is core to my app's feature set.

    Thanks in advance.
     
  13. Aram-Azhari

    Aram-Azhari

    Joined:
    Nov 18, 2009
    Posts:
    142
    I have this problem too. It's interesting that it always happen in the editor, and for some project it's fine on iOS device.
     
  14. memetic-arts

    memetic-arts

    Joined:
    Feb 27, 2011
    Posts:
    82
    I finally resolved both of these issues.

    For the scene-switching issue, because the scenes are derived from a shared template, some of the included items/prefabs had the same name, which, I think, created an issue with caching. Because I'm loading additively, old, similarly-named components/elements were not being removed, despite explicit unloading of the scene. I tried changing the names in each scene to unique names, and that was only partially successful. In the end, I've had to include a Caching.CleanCache() statement, which, while not ideal, is the only thing that seems to force the full loading of a new scene.

    With regard to the pink-shader issue, the answer here is that within Edit>Project Settings>Graphics, you need to include your shaders in the "always included shaders" section. I then created an sv file, added it to my textures folder and included it in a bundle. I also, within the core/root scene, added that file to the "Preloaded Shaders" section of the Graphics project settings. Not sure if all of that is necessary, but it seems to work!