How to copy meshfilter from probuilder component to gameobject?

Hello,

I have a problem I cant solve without some help, and I couldnt find any on the internet so far.
I have used the pro builder to merge some meshes.

Now I am implementing a save/load system. After loading, I check which type of prefab it is and I am copying the meshfilter and materials from the prefab to the gameObjects.

But with the prefabs that I have edited with the pro builder it is not that easy because I dont know how to get the mesh from the ProbuilderMeshFilter component and put it into a new ProBuilderMeshFilter component.

Or if that is the wrong approach, how can I get the meshes from the prefab to the gameobject if the mesh has been made by the probuilder?

Thank you in advance!

well you can export it to fbx and have it import back in and use it

Can you maybe give a little snippet what you mean? I have absolutely no idea how that works in the code.

this is how it works for normal component:

                    MeshFilter prefabMeshFilter = prefabModels.GetChild(i).GetComponent<MeshFilter>();
                    if (prefabMeshFilter != null)
                    {
                        MeshFilter targetMeshFilter = models.GetChild(i).GetComponent<MeshFilter>();
                        if (targetMeshFilter == null)
                        {
                            targetMeshFilter = models.GetChild(i).gameObject.AddComponent<MeshFilter>(); // Falls noch nicht vorhanden, hinzufügen
                        }
                        targetMeshFilter.mesh = prefabMeshFilter.sharedMesh;
                    }

The Probuilder MeshFilter that you see in the inspector is just ProBuilderMesh under the hood. So to get the mesh from a pb prefab, based on your code, the below should work:


ProBuilderMesh pbMesh = prefabModels.GetChild(i).GetComponent<ProBuilderMesh>();
...
targetMeshFilter.mesh = pbMesh.mesh;