I'm using Unity Editor with C# as programming language.
My question consists of two parts. In my situation I'm trying to save everything in my scene into a JSON file. And then loading it in a new Scene for reasons. You could read this question to get a general idea why: Unity save everything (snapshot)
So I'm trying to save my mesh in scene one. Then I have scene two which is empty and I'm trying to load it from scratch from a JSON file. I need to save something of the mesh so I can point at it when I load the objects in the new scene.
My current idea of saving: I need to split because for example I have a sphere object, I get "Sphere Instance" when calling the name variable. The split will remove the " Instance" part.
mesh = meshfilter.mesh.name.Split(' ')[0];
sharedMesh = meshfilter.sharedMesh.name.Split(' ')[0];
So now in my JSON file I have "Sphere". So my next step is to build the new scene from scratch with this information.
So I use this code:
meshFilter.mesh = Resources.Load(mesh) as Mesh;
meshFilter.sharedMesh = Resources.Load(sharedMesh) as Mesh;
Unfortunately the resources.load will be null. In my test I use primitive and custom meshes.
Hopefully one of you can see what's wrong or tell me of a better way to save/load which works with the situation described.
Thanks for any help you can provide.