I’m adding a submesh to a model in AssetPostprocessor.OnPostprocessAllAssets, and then building a prefab from it with PrefabUtility.CreatePrefab.
It works fine until I restart the editor, and then the changes to the model are shown to have been ephemeral; neither it nor the prefab retain the new submesh.
What’s the trick to making lasting changes to a model, or at least saving a new mesh?
static def OnPostprocessAllAssets( imported as (string),
deleted as (string),
moved as (string),
movedFromAssetPath as (string) ):
for assetName in imported:
if assetName.EndsWith('Ship.obj'):
modelName = assetName.Replace('.obj', '').Replace('Assets/models/', '')
mesh = AssetDatabase.LoadAssetAtPath( assetName, Mesh )
BuildWireFrame( mesh )
go = GameObject( modelName )
mf = go.AddComponent[of MeshFilter]()
mf.sharedMesh = mesh
renderer = go.AddComponent[of MeshRenderer]()
renderer.materials = (
AssetDatabase.LoadAssetAtPath( 'Assets/materials/RimLight.mat', Material ),
AssetDatabase.LoadAssetAtPath( 'Assets/materials/WireFrame.mat', Material )
)
PrefabUtility.CreatePrefab( "Assets/prefabs/" + modelName + ".prefab", go )
EditorApplication.SaveAssets()
EditorApplication.SaveScene()
GameObject.DestroyImmediate( go )