x


AssetBundle.Unload(false)

I had a previous discussion in regards to Unloading asset bundles after downloading them. In the reply Lucas had mentioned that it is always a good idea to unload the bundles to free up memory. However, I am a bit confused when it comes to scenes that reside in asset bundles. For instance, see the below code snippet. If I unload the asset bundle after loading the scene, I assume that the asset bundle will be removed from memory and the scene is still in memory. However, this is not the cause. Unloading the asset bundle seems to be unloading the entire scenes contents. Based on the documentation for Unload, passing a value of false to it indicates that this behavior should not be occuring??? Am I missing something here?

public IEnumerator LoadScene()
{
    WWW stream = new WWW("assetBundles/dynamicScene.unity3d");

    yield return stream;


    AssetBundle bundle = stream.assetBundle; 

    // Load a scene that was stored in the asset bundle.
    Application.LoadLevelAdditive("dynamicScene");

    // This will cause everything in the scene to be unloaded.
    bundle.Unload(false);
}
more ▼

asked Apr 20 '10 at 09:40 PM

Bill gravatar image

Bill
311 20 24 36

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

The issue is that Application.LoadLevelAdditive is delayed until the next frame. Thus you are actually unloading before the level has been loaded.

You can add a yield between LoadLevelAdditive and Unload, then it should work. Better use LoadLevelAdditiveAsync and yield the result.

more ▼

answered Sep 26 '10 at 06:01 PM

Joachim Ante gravatar image

Joachim Ante
950 5 8 24

(comments are locked)
10|3000 characters needed characters left

Report a bug with a small sample.

While loadleveladditive does not technically load the scene as a scene but add it into the current one, instantiated stuff should be kept alive too and does so if you instantiate it directly or if you used loadlevel there

more ▼

answered Aug 15 '10 at 12:09 AM

Dreamora gravatar image

Dreamora
3.3k 1 4 25

I had happen to just copy and past some code I was experimenting. But it doesn't matter if the level is loaded additively or non additively. The same behavior occurs. From my own research, scenes in asset bundles tend to work slightly differently then regular assets when loading and unloading. I'm not sure if this was by design or not. However, I had a discussion with them about this in the unity 3.0 alpha mailing list back in May, so they are aware of the problem.

Sep 01 '10 at 02:17 PM Bill
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x744
x548
x397

asked: Apr 20 '10 at 09:40 PM

Seen: 2889 times

Last Updated: Apr 20 '10 at 09:40 PM