- Home /
Efficiently create hundreds of meshes
[UnityScript] So in my project there is a need to create the map procedurally (in runtime). However simple it requires to make hundreds if not thousands of a single prefab then combining them into a couple meshes. This obviously gets pretty messy to code and is a hard hit to the CPU for a couple seconds. Is there any other way besides instantiating every single segment then combining them into a couple meshes because this seems like a crude way to do it. Or is there a way that makes it easier on the CPU, and quicker?
Answer by Waz · Jul 29, 2011 at 11:05 PM
Rather than generating the pieces as objects that you then combine the meshes of, the alternative is to build the (combined) mesh directly. See the Mesh documentation for details.
I don't really see anything on the doc, can you point me at a function or instruction that can help?
That documentation shows how to build a $$anonymous$$esh from scratch. That's the way to get the performance you desire.
So I would take the vertices of every mesh I want to build in each segment then create a mesh of them all. Cool
Correct. You can look at the CombineChildren script for a big example. Indeed, you could make your script based on that, since it ultimately boils down to a list of meshes and positions, exactly as you have.
Better still, the $$anonymous$$eshCombineUtility script which is uses to do the actual combining looks exactly like what you want!