Quantcast
Channel: Questions in topic: "assetbundles"
Viewing all articles
Browse latest Browse all 312

How do I create commen asset bundles from multiple scenes

$
0
0
Hello, Im hoping someone can help with assetbundles. I am attempting to create bundles to minimize my disk space footprint on Android. I have a number of scenes that use the same prefabs(props) and terrain. A single scene is about all the device can load with the device's given memory. My hope is that I can create a common prop asset bundle, and a common terrain asset bundle from the scenes. From these bundles I thought I could load the correct bundles and then load a scene. (note the entire process would encompass 3 different sets of props subsets and a terrain) Example of this (simplified!!) Terrain - T1 - T2 - T3 Props - A - B - C - D - ... Scenes - S1 uses T1 and A &B - S2 uses T1 and B,C&D - S3 uses T2 and A&C - S4 uses T2 and B&D - ... and so on Here is the code im using to create my list of asset objects, (side note: I am using a call to GetDependencies on the scene.unity file and intersecting that with my prop path to get only the prop prefabs which are passed to the code below to gather only the props and their dependencies) public HashSet m_assetPathNames; ... string[] dependencies = AssetDatabase.GetDependencies(new string[] { prefab}); foreach (string d in dependencies) m_assetPathNames.Add(d); Once I have collected the unique set of assets and their dependencies, I call this {m_dataToSave is a List<> created from the hashset) BuildPipeline.PushAssetDependencies(); Object[] assets = m_dataToSave.ConvertAll((x) => { Object o = AssetDatabase.LoadAssetAtPath(x, typeof(Object)) as Object; return o; }).ToArray(); if (assets.Length > 0) BuildPipeline.BuildAssetBundle(null, assets, fileName,BuildAssetBundleOptions.CollectDependencies| BuildAssetBundleOptions.CompleteAssets | BuildAssetBundleOptions.UncompressedAssetBundle,BuildTarget.Android); This is called for each of the bundles, finally, I have this code is called for each scene, for (int i = 0; i < m_scenes.Count; i++) { BuildPipeline.PushAssetDependencies(); BuildPipeline.BuildPlayer(new string[] { m_scenes[i] }, bundleLoc + "Scene" + i+".unity3d", BuildTarget.Android, BuildOptions.UncompressedAssetBundle); BuildPipeline.PopAssetDependencies(); BuildPipeline.PushAssetDependencies(); BuildPipeline.BuildStreamedSceneAssetBundle(new string[] {m_scenes[i]},bundleLoc+"sbundle"+i+".unity3d",BuildTarget.Android); BuildPipeline.PopAssetDependencies(); } Problem is that the streamed asset bundle and the player's size doesn't change depending on whether I build the prior asset bundles or not or pop after each is built. From the docs it seemed like this was what was supposed to happen but it isn't. Am I missing some basic step? Is this the appropriate use for asset bundles? If you believe you need more code let me know, I will add it. But I believe the basics of what I am doing is in the code sample above. I debugged the entire process verifying that the assets that should be in each data structure are correct and expected. I have assetbundles being built, whose sizes seem correct. I have played with the buildsetting enums... but will try others if you believe there is a mistake there. Thank you for reading, and for any that can help!

Viewing all articles
Browse latest Browse all 312

Trending Articles