Unity 2018.3 saving Mesh references from Play Mode

I’m working on a Level Design Tool running in Play Mode.
When user saves the map (in Play Mode), I use PrefabUtility.CreatePrefab() to create the map on disk. Because Unity looses all references to meshes, I restore them in the newly created prefab by setting MeshFilter.sharedMesh. This does work prior to 2018.3 (new prefab system).

Is there any way to restore Mesh references or carry them from Play Mode into a prefab in Unity 2018.3?


Ok, found a work around. The trick is to load the newly created asset by AssetDatabase.LoadAssetAtPath() and set the Mesh there.

        public void CreatePrefab()
            // called by button, save prefab to disk, overwrite if there

#if  UNITY_2018_3_OR_NEWER
            GameObject newPrefabOnDisk = PrefabUtility.SaveAsPrefabAsset(newPrefab, PrefabLibSelector.GetScenePath() + "/Resources/" + prefab.name + ".prefab");
            GameObject newPrefabOnDisk = PrefabUtility.CreatePrefab(PrefabLibSelector.GetScenePath() + "/Resources/" + prefab.name + ".prefab", newPrefab);

            // Unity prefab bug  workaround, meshes must be restored from prefab into new prefab
            GameObject o = AssetDatabase.LoadAssetAtPath(PrefabLibSelector.GetScenePath() + "/Resources/" + prefab.name + ".prefab", typeof(GameObject)) as GameObject;
            MeshFilter[] allMeshesInPrefab = prefab.GetComponentsInChildren<MeshFilter>();
            MeshFilter[] allMeshesInNewPrefab = o.GetComponentsInChildren<MeshFilter>();
            for (int i = 0; i < allMeshesInPrefab.Length; i++)
                allMeshesInNewPrefab_.sharedMesh = allMeshesInPrefab*.sharedMesh;*_