If I want to create a level using code, I know I can draw a custom mesh and add verts and tris, but can I add an existing whole mesh to another mesh? In this way, I can have pre-made level chunks and add them together.
Another pertinent question might be, do I even need to do this? Is there a performance benefit to doing it this way? Will using one custom mesh for the level be faster than instantiating many prefabs and leaving them as separate meshes?
You can use the Mesh class to access mesh data and create new meshes that can combine the features of existing ones (there’s even a helpful CombineMeshes function that will often do most of the work for you). The issue of whether to combine meshes or use separate objects depends heavily on the situation in the game. If you have a lot of low detail objects with just a few triangles each in close proximity, you will usually benefit from combining them. An example would be roadside bollards in a driving game. However, if any part of an object might be visible then the whole object must be rendered, so it’s not usually a good idea to combine widely separated objects that won’t be seen together on the screen at the same time.
Great, that function is exactly the one I’m looking for. Though I’m starting to rethink my whole strategy on the level building… think I might do it in the editor after all, it’ll give me more creative options. Useful to know about the performance issues though, thanks!