I’m trying to wrap an imported model in a prefab, but while I get the right contents, certain components are missing. I’m feeding the imported GameObject (in OnPostprocessModel()) to PrefabUtility.CreatePrefab(), and the resulting prefab has the mesh, but the meshfilter’s mesh is empty. What’s that about?
Here’s a simplified version of the code:
public void OnPostprocessModel(GameObject gameObject)
{
var isZombieElement = assetPath.ToLower().Contains("models/zombies/");
if (isZombieElement)
{
var prefab = GetOrCreatePrefab(gameObject);
}
}
I’ve attached an example project that includes a good old teapot.fbx and barebones custom processor. You can see that the generated Prefab is kinda empty (no mesh in meshfilter)
The correct place to copy assets is in OnPostProcessAllAssets, only at this point in the asset pipeline has all the information been correctly written to disk.
How are you supposed to get a reference to the imported object with this “upgrade?” With OnPostprocessModel, it was inherent. OnPostprocessAllAssets only gives you the name of the model you’re importing.
Edit: Figured it out for anyone who’s curious. Use AssetDatabase.LoadAssetFromPath to get a reference to the GameObject. It would be helpful to put in that Unity 4 Changes Documentation.