- Home /
Reducing drawcalls - Many Prefabs vs Combined Mesh
I am in the process of creating an urban environment, and would like some advice as to how to manage the potentially large number of assets, in this case buildings. If one building model with one material/texture, is used as a "starting block" to create multiple streets (and eventually a city like environment) which of the following techniques is best for minimizing draw calls:
One Building prefab duplicated many times, positioned side by side etc
OR
One City prefab, with all of the buildings already combined into one mesh in a modelling package
I am unsure if Unity renders a prefab and all of its instances only once (which would make sense), or if it treats every instance as if it were a separate mesh/object. Another obvious factor to consider is clipping planes and culling layers. If one mesh is used for an entire environment, clipping planes will no longer be useful for culling certain parts of this environment based on distance. Therefore the entire environment would be continuously rendered no matter where in it the player would be, which seems quite a waste of resources.
There may be a better approach than the two I have listed above, so please if anyone has advice on a better technique than what I propose please let me know. Thank you.
Answer by Hamesh81 · Nov 15, 2011 at 02:22 PM
This is quite simple really hey. Firstly, 3 prefabs in a scene will still have the same triangle count as the original 3 meshes (ie, one 12 triangle cube instanced 3 times will be 36 triangles in your scene), but they will only need one draw call irrespective of how many of them are in the scene. If the meshes have a larger amount of triangles (can't remember the limit exactly, but it's quite low) though they won't get "batched", meaning that each instance will create an extra drawcall. What u need to consider is whether u want 2 (a) keep meshes combined as much as possible, or (b) have them broken down into prefabbed "building blocks" (as u put it).
With many prefabs u'll able 2 take advantage of culling to reduce draw calls; with combined meshes u may be able to reduce the draw calls even more but imo will lose some flexibility and the memory needed to load your massive model. For example, if u're entire city (or even large parts of it) is one mesh, if u need 2 change/re position just one building u won't able 2 do that directly in Unity, u'll have 2 go back 2 the source and let it re-import (which personally kinda annoys me).
It's up 2 u how you go about it!
I'd actually completely forgotten about this question since nobody gave any comments or suggestions. But thank you for your response, it's answered all of my questions.
Answer by demonpants · Mar 07, 2013 at 10:56 PM
My solution is to keep the objects separate in the level editor and the Unity scene, then when the level is loading up for the player combine all the meshes. It's fast enough that it doesn't increase load times too much, and in some levels I saw a 500% FPS increase with doing this. Best of both worlds.
For stuff that needs to be separate for animations or whatnot, I simply tag those objects and they don't get combined.
Thats another question. Do a web search, if you cant find the solution. Post a question.
Your answer
Follow this Question
Related Questions
Prefab Materials and Meshes being deleted, How can I stop this 1 Answer
Dynamic batching not working? 0 Answers
Graphics.DrawMeshNow ( Does it work on OSX Capitan ) 0 Answers
duplicate a prefab then change the model? 1 Answer
I can modify the GameObject transform using the inspector, how can I modify the mesh as well? 0 Answers