Procedurally generated mesh saved twice in scene

I have a component that procedurally generates its mesh. Its GameObject is based on a prefab. The (re)generation looks like that:

DestroyImmediate(mf.sharedMesh);
var mesh = new UnityEngine.Mesh { name = $"{name} (Generated Mesh)" };
updatedMesh.ApplyToUnityMesh(mesh);
mf.sharedMesh = mesh;

Now, when I instantiate the prefab, the generation runs and everything is fine. I can also change parameters and the mesh gets correctly regenerated. However, if I save the scene, there are now two meshes in the .unity file.

--- !u!43 &1699566314
Mesh:
  m_Name: Rubber1 (Generated Mesh)
...
--- !u!43 &1050816235
  m_Name: Rubber1 (Generated Mesh)
...
--- !u!1001 &1084441717
PrefabInstance:
  m_ObjectHideFlags: 0
  serializedVersion: 2
  m_Modification:
    m_TransformParent: {fileID: 241506051}
    m_Modifications:
    - target: {fileID: 4392546155774236836, guid: 073cf4ebd8b550b4699ac09545ec5673,
        type: 3}
      propertyPath: m_Mesh
      value:
      objectReference: {fileID: 1699566314}

So one of the meshes is referenced in the prefab modifications, and the other looks like an orphan.

Does anyone have an idea what the cause of this might be?

Hi @phreezie . If you think this is a bug, please file a bug report and attach a minimal repro project. Just follow the steps on this page: Unity QA: Building quality with passion. Thanks.

Well, from my understanding, Unity keeps the original values of overridden props in the game object in order to be able to easily restore them. So I don’t think it’s a bug, it’s just that mesh data is somewhat large, and I wondered if there’s a way to clean this.