- Home /
how can I export a prefab modified from fbx model?
There is my operation:
drag fbx model to hierarchy.
modify game object structure.
create prefab of the game object.
export prefab to Asset Bundle.
load Asset Bundle through WWW.
When I load the game object from AssetBundle, the structure is same as original game object that created by dragging fbx model to hierarchy. And I found if I substitute the material and delete origin material in step (2),the game object load in step 5 change to pink.
Is anyone know how to fix it or give another method to fulfil the need of exporting the prefab modified from fbx model.Thanks!
You question is hard to read. What is your step (2) and step (4) actually doing? Pink means a shader cannot be found.
Anytime you delete a material that is used by some object, that object will turn pink to notify you of a missing material.
@Subhajit Nath ,I substitute material to another.And it works before step 3.But in setp5,it turn to pink.
Answer by VatelsRevenge · Aug 29, 2014 at 12:46 AM
I've been running into similar issues. I fixed mine by making sure my fbx has a different name than the prefab I generate. It's almost as if sharing the same filename causes unity get confused as to what it should do.
From what I can tell, if the fbx and the prefab share the same name (extension doesn't matter) then when I load the prefab from the asset bundle it'll try to load either the fbx or the prefab. And of course, if it loads the fbx, it will be wrong and missing dependencies because I changed them on the prefab.
Makes me wonder if adding a prefab to an asset bundle causes a bunch of things to be added (materials, textures, fbxs) and everything is defined in the asset bundle by file names without extension or directory. Which would be terrible.
Answer by miron83 · May 13 at 09:49 AM
It's not bad idea to name model and prefab the same, however it's true that usng just name without an extension, unity will pick fbx over prefab. Therefore the best and safe practice is to check all attached elments in asset and look for a prefab:
public GameObject LoadModelFromFile(string _filePath, string _modelSlug)
{
AssetBundle _Bundle;
_Bundle = AssetBundle.LoadFromFile(_filePath);
bool _prefab = false;
foreach (string _s in _Bundle.GetAllAssetNames()){
_prefab = (_s.LastIndexOf(_modelSlug + ".prefab") > -1) ?true:false;
}
GameObject _Obj = _Bundle.LoadAsset(_modelSlug + ((_prefab)?".prefab":"")) as GameObject;
_Bundle.Unload(false);
return _Obj;
}
Safe because you can also have assets without a prefab and thanks to checking the asset boundle first you're sure that it wont run into an error.
Just remember that when you making a prefab from fbx, before exporting them to asset boundle, make sure to choose a "prefab variant" not "original prefab". Otherwie your prefab will not have meshes or other fbx attributes attached to it. Don't forget to change the name after doing so, as editor will add " Variant" to the name...