Unity 5 Asset Bundles with uGUI

Hi all,

Our team works on complex mobile game with a lot of UI. We decided to use Asset Bundles system to divide SD (for small resolution) and HD version (for high resolution). Our main goal is huge memory optization on low-end devices like iPad mini 1/2, iPad 2 etc.

As you know uGUI system works with sprites. We pack all sprites in atlases with sprite packer. We store our UI screens as prefabs and pack them with asset bundles.

We have three main bundles for UI:

  1. Main Menu UI - UI prefabs (screens, popups), sprite atlases - used only in main menu;
  2. In-game UI - UI prefabs (screens, popups), sprite atlases - used only in gameplay;
  3. Common UI - UI prefabs (screens, popups, panels), sprite atlases (fonts, buttons, backs) - used in whole game;

Each bundle stores their own atlases and prefabs. But we also have many prefabs from 1st bundle which uses atlases (sprites) from 3rd bundle. When we instantiated this kind of prefabs, atlases from 3rd bundle duplicate in memory again and again without reusing. I think it’s very strange behaviour. And it’s not documentated anywhere.

The main question is how to use bundles with cross-dependecies without memory leak? How to enable reusing of already loaded resources (in our case - atlases) from specific bundles?

You need to have all dependent (shared) assets in their own asset bundles, such that a dependency is created between your top level bundles and the assets they share.