Loading / generating meshes at runtime

[Edit: I posted this on the wrong forum. I created another thread under graphics (which i guess is more adapted).]

Wanting to create a metroidvania platformer, I thought i might first create a map editor to have a nicer workflow. I started using sprites, but then i decided to learn how to create meshes. Thing is, it is exceptionally more complex and i don’t understand everything.

It is map editor working at runtime that consists in creating meshes using points and triangulation with automatic UV mapping, creation of edges colliders according to the points. Then hitting save, it will have to create a file ( using binaryformatter/json/xml, i’m not sure yet ) holding all the infos of each mesh, the infos about edges colliders. (i don’t use mesh colliders).

After that, in another Scene, i need to read all the data of the created level and create again those meshes during runtime. Thing is, i need those meshes to load smoothly, as i will need to load the level 2 as the player is approaching it without loading screen (and without loosing too much framerate).

One level contains something like 200 meshes, each mesh having around 18 vertices. They all use shared materials, with something like 30 different materials ( mostly 64x64 pixels textures set to repeat).

How should I save all those meshes as one file on the HardDrive? Should I just save the vertices and UV? Should i store everything from them, vertices, uv, triangles, normals ( maybe there are other things to store i’m not sure).
Is a serialized class saved as a file using binaryformatter the best way of doing it?

How should I load them nicely after that ?
Before, i was using object pooling and was setting sprites at the right location one by one every frame using a list of Vector3 stored on such a file. Can i do such a thing with meshes?
Is creating lot of meshes at the start of the game, then modifying their position/vertices/uv/materials during runtime one by one every frame / in a coroutine an efficient way of doing it?

Is the Mesh.MarkDynamic adapted for such an use? (I’m not 100% sure of what it does).

I started creating this editor a few weeks ago, reading during my breaks everything i could find about mesh generations , but I wasn’t able to understand / find things looking like what I need.
Thanks a lot for reading my long post, I hope i acheived to explain myself correctly.

https://forum.unity.com/threads/generating-saving-loading-meshes-at-runtime.498743/

You should only save the map data, and create the meshes from that at runtime. Saving all the mesh attributes would result in a lot of unnecessary data. Having each mesh be only 18 vertices is a big waste; you should use far more than that (up to 65K). Unless you’re doing something super-fancy or have more tiles than you can fit in a single atlas, there should be only one material. There’s no reason to set anything every frame, and that’s a bad idea in general. Especially with meshes you would create them once, and only make changes if any tiles change.

–Eric

[Uh, actually, you answer was so quick, now i have two times the same post in two forums, sorry :s ]

Actually, i’m note sure about how I can make textures repeat using an atlas. Using google, it appears I need to modify the shaders, i don’t know how to do that yet, but i will try to find out.

If I combine all the meshes into a big one (making actually the entire level be one mesh), won’t trying to create it again during runtime make the game freeze for hundreds of milliseconds?

What i was wondering is, performance wise, when i’m leaving a room and entering another, is it better to take the meshes from room1 , modify them and put them in the room2, or just to create new meshes and put them in the room2 and get rid of the meshes that are in the room1?