- Home /
Create an AssetBundle with prefabs containing imported models
I'm trying to create an AssetBundle containing a model imported from Maya, using the script provided in the Unity scripting reference. I need to instantiate it at runtime, and I've put it in a prefab because it needs to have a collider and a custom script (a script already compiled with the WebPlayer). The problem is that sometimes the prefab gets saved with the whole imported mesh, sometimes it just references it, you can tell from its size. Also, I've created AssetBundles with these models several times, even trying to include in the bundle the original imported mesh. Sometimes it worked, sometimes it threw an error during runtime saying "The prefab you're trying to instantiate is null". The success probability of the building process seems random. Perhaps I'm doing something wrong?
So, how do I make sure that the prefab I'm creating contains the actual mesh? And what is the best way to instantiate it from an AssetBundle? If it can help, that's the code I'm using (in UnityScript, unfortunately I don't know the C# yet):
var ThisAssetBundle = www.assetBundle;
//Loads a specific object from the AssetBundle
ObjectLoaded = ThisAssetBundle.Load("objectname");
ObjectInstantiated = Instantiate(ObjectLoaded, Vector3.zero, Quaternion.identity);
can you provide your asset bundle building code? If I would have have to guess you forget to add the flag to build the asset bunlde with deep references so it includes the mesh, hence its only present when you selected it to be included manually
I'm using the script provided here: http://unity3d.com/support/documentation/ScriptReference/BuildPipeline.BuildAssetBundle.html I've obviously tried both options, "Track dependencies" and "No dependency tracking". Probably I should write my own script though.
Your answer
Follow this Question
Related Questions
Prefab instantiating at wrong position in mobile 1 Answer
Missing Material in AssetBundle Prefab 3 Answers
Dynamic object Instantiate 1 Answer
Prefabs not visible in webplayer? (read from .txt file) 1 Answer
Prefab instantiating problem 1 Answer