- Home /
Can I use Prefabs instead of Scenes for AssetBundles?
Hey everyone,
Just wanted to sanity-check an idea we've been throwing around. It came as a bit of a blow to us that you can't include scenes in asset bundles, since we were counting on this to deliver level packs for our Android/iOS game. I've heard that the ability to do this will be included in Unity 3.4, but we can't really count on that releasing before we launch.
As an alternative, we were thinking that we could create a prefab that includes all the unique elements of a scene and then include that prefab in an asset bundle with a name like "Pack2_Level3". So, essentially, we would be creating a prefab with all the level objects as children, naming it uniquely, and then packing it into an asset bundle.
Then, on the other end, we have a basic level with common elements, and we can then call
AssetBundle.Load("Pack2_Level3")
to create unique levels without including scenes in asset bundles.
Does this seem reasonable? Has anyone used this method before? Are there any potential issues or limitations that I'm missing - ie memory on mobile devices, time required to load prefabs, prefab size? I feel that this idea is conceptually solid, but there might be some practical issue that I'm unaware of.
Answer by kdubb · Jun 02, 2011 at 02:28 AM
Not exactly an answer to your question but I am not sure you cannot do your first choice! Have you looked at BuildPipeline.BuildPlayer, specifically with the BuildOptions.BuildAdditionalStreamedScenes option? It allows you to download extra scenes (with assets included) in an asset bundle. I think what trips everybody up is that you cannot simply include scenes into the BuildPipeline.BuildAssetBundle call instead you must use the other BuildPlayer method to include them.
As an answer to your question...
This is exactly how you would create these extra levels (if you do not opt for the more direct method stated above). We are using something similar but we are using one asset bundle for the environment, another for the vehicle, another for the vehicle skin, etc. so that we can have a number of dynamic elements.
As far as memory goes just unload the asset bundle, and all the unused assets with it, and Unity will somewhat automatically reduce your memory requirements to the bare necessity.
As for loading time, on the iPhone (3GS+) and iPad has been nominal and for most of our stuff almost unnoticeable.
Cool, thanks for the info! Have you had any luck using the StreamedScenes method? We had been under the impression that scenes couldn't be included from this forum post by the Unity CTO: http://forum.unity3d.com/threads/41638-No-BuildOptions.BuildAdditionalStreamedScenes?p=566632&viewfull=1#post566632
Thanks for the tip, we'll try this out in the next few days.
(btw, I am the original poster, but am unable to login with that account due to a server error page - new unity answers needs some work!)
Your answer
![](https://koobas.hobune.stream/wayback/20220612093959im_/https://answers.unity.com/themes/thub/images/avi.jpg)