Still trying to wrap my head around memory usage, asset bundles, and prefabs

Hi Gang,

Let’s say I have this current setup:

  1. a few dozen prefabs in one asset bundle (built with CollectDependencies|CompleteAssets)
  2. a game-level content API layer that I have to use to get the AB data in as a byte[ ] array
  3. Before I load my actual gameplay level I call AssetBundle.CreateFromMemoryImmediate() on this byte[ ] array and cache the resulting asset bundle by name.
  4. I then call bundle.Load(…) to obtain the prefabs I want and also cache them by name (inside my AssetManager layer)
  5. As I’m loading the level, I’m calling GameObject.Instantiate() on the cached prefabs that I obtained in step 4)
  6. When I finish loading the level

ARG clumsy sausage fingers!

  1. When I finish loading the level, I release references to my cached stuff:
    a) I call bundle.Unload() on the cached AssetBundle instances I obtained in step 3)
    b) I remove references to my prefabs cached in step 4) by removing the appropriate dictionary entry

I do all this to try to make my gameplay level as lean as possible. However doing Step 6 seems to unload everything from my game, even those game objects that I duplicated from the cached prefabs in Step 5.

Does anyone know why freeing up my prefabs (which I only need at the beginning of the level and which I’m duplicating) results in the duplicates being removed?

Bump. I’m also making sure I’m calling AssetBundle.Unload() with the unloadAllLoadedObjects parameter set to false, which (according to the docs) shouldn’t touch the objects I created from the bundle.