optimization - Unity 4 - using AssetBundle to pre-load assets that are shared across multiple scenes? -


i have several areas in game project split on several scenes, instance let's there first area called "basement" split in basement_1, basement_2 , basement_3 scenes; , area, "attic", split on attic_1 , attic_2.

some assets (textures atlas , sounds) shared across scenes of area , thought make assetbundle shared assets "basement", , assetbundle shared assets "attic" area. when player enter "basement" area, i'd load "basement" assetbundle, when call application.loadlevel("basement_1"), application.loadlevel("basement_2") or application.loadlevel("basement_3"), shared assets (which have been loaded in bundle) aren't unnecessarily reloaded, scene-specific assets loaded. if point game knows basement assets no longer necessary, or not long time @ least, i'd unload bundle, free memory, , load whatever other bundle may relevant (the attic 1 instance).

my question is: how works? in, i'm enter "basement", if load "basement" assetbundle disk, , call loadallassets() on it, application.loadlevel("basement_1") "automatically" assets in bundle i've loaded? or application.loadlevel reload assets needs anew?

my current understanding application.loadlevel not automatically in assetbundle. if so, there way make in loaded assetbundle(s) ? there way i'm not seeing?

the idea try reduce loading times, because instance going in , out of door trigger call application.loadlevel("basement_x") , application.loadlevel("basement_y") , forth.

thanks in advance insights ;)

cheers!

asset bundles can used way proposing, used resolve issue of downloading content server. basically, if not planning have being downloaded, don't have many reasons use asset bundles.

prefabs, on other hand, seems need. game objects "pack" prefab can reused. if want re-use game object, in same scene or on different scenes, prefab way go.

if programmatically instantiating , positioning game objects, this:

gameobject myitem = instantiate(resources.load("myprefab")) gameobject; 

given myprefab prefab inside folder called resources.

if creating scenes in editor, you'd drag , drop prefabs scene, they'll become regular game objects.

you can optimize game object usage between scenes using object.dontdestroyonload prevent objects of being destroyed. i'd highly recommend use if absolutely not changing. such premature optimization (of reusing objects) can potentially cause unthought problems , delay development of game.

that said, keep in mind if keep reference loaded prefab, asset bundle, game object or whatever, never garbage collected, can make use of object.dontdestroyonload and/or static references keep them in memory.


Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -