Altering existing prefab asset with editor script

I have an editor script that generates textures, materials and meshes, then for each pair generates a GameObject with a MeshFilter and a MeshRenderer so it can be dropped straight into the editor (this mimics what you get if you import a model file manually).

The first time this is fine - I use AssetDatabase.CreateAsset and everything works. The second time however I cannot figure out how to update the existing asset - there doesn’t seem to be anything like AssetDatabase.UpdateAsset(). If I call LoadAssetAsPath I can get the current asset, but I cannot see how to update it - just setting the attributes does not actually affect the asset on disk (and no, AssetDatabse.SaveAssets does not work for this).

Currently I can only delete the existing asset, then create it again. However this break all existing instances of these assets (presumably because it’s got a new GUID).

How can I update an existing asset file on disk while retaining it’s existing GUID and editor instances?


EditorUtilty.SetDirty() will flag the asset with changes, such that saving the unity scene will save any changed metadata?