I'm currently working on a Unity project with Minecraft-like world generation. The goal is to generate different blocks in the world, each with their own Material, and then combine them into one big mesh. My problem is that this comining removes all of their Materials (since the new mesh can only have one material). I've heard about a method using a so called texture atlas but couldn't find anything specific so my questions are

* how do I combine multiple meshes into one big mesh whilst keeping different materials (it should preferably be just one mesh, not multiple ones for different material groups)?
* if that doesn't work, how do I automatically generate a texture atlas that can display different textures for different triangles?

One thing I tried was generating a mesh for every cube in the world and then combining them into bigger meshes, but this lost all material data which looked like this:
[Single meshes on the right, big mesh on the left](https://i.stack.imgur.com/bWT2j.png)

Thanks in advance!