- Home /
lowering draw calls
I have a situation where i have an cubePrefab object that i instantiate to create a grid of 120 cubes at the start of a level. They all have the same material, but use a texture atlas to display one of 8 different colors. Currently, I have about 140 draw calls happening in my game. Given this situation is there any room for lowering my draw calls, or should I look else where?
The only other objects i have are a cube with has a black material on it, three other cubes, each with there own material, and two GUI_Text objects, that are using standard unity fonts to display (nothing imported or used as a new font)
I've read other posts, but it seems that most answers lead to combining meshes, but this cubePrefab needs to move around, be destroyed, recreated, yadda yadda... is this still the way to go?
any tips? thanks unity answers!
Answer by Bampf · Jan 14, 2011 at 10:02 PM
Not sure how you are doing the texture atlas, but something is preventing Unity from combining the cubes into one draw call.
If you instead had a simpler setup: 8 different cube prefabs, each with its own material with a single texture, I believe you'd end up with only 8 draw calls for all the cubes.
Try a test case making copies from a single cube prefab. Once you can do that in a single draw call, you can either clone that 8 times, or use what you've learned to try to figure out what it is about your original solution that's confusing the engine.
See also this answer: http://answers.unity3d.com/questions/15567/dynamic-batching
Edit: Here is a useful forum discussion about other things that can interfere with batching. Multipass shaders apparently won't, for example. In addition, when running in the editor in Deferred lighting mode, apparently some shaders run multipass even though they wouldn't on an actual iOS device. (Setting Edit->Graphics Emulation correctly might be enough to fix that.)
Heh, I could totally be misinterpreting what a texture atlas is. essentially, I have a diffuse material with a texture (that looks like a sprite sheet) and that material is on the cubePrefab. is there a different way to set it up?
I did the test, and it seems i get one call per object in my scene, could i be doing something else wrong? THAN$$anonymous$$S in advance!
Could it have anything to do with each of these cubePrefabs having different values for their variables?
I found a useful forum discussion about things that can interfere with batching. I added a link to it to my original answer.
Answer by Tzan · Jan 17, 2011 at 01:10 AM
The draw calls you are seeing is normal for what you are doing.
You need to write a custom Combining script.
Create an empty GO parent object Make all the cubes children of that parent.
The children have their renderer turned off. Any colliders will still work, because the GO is still active. They get combined into the parent.
When a change happens to a cube, you combine the child meshes into the parent again.
I do this with 1024 "cubes" in less than 30ms, last time I checked. i7-920, Radeon 5870
I dont do animation with them, just manual editing. If you where sliding boxes around all the time, that might be a problem.
I use Mesh.CombineMeshes()
Answer by FriedrichWessel · Nov 18, 2011 at 12:27 PM
Just for the Record: The Problem is that you create your Cube bei Instancing an prefab. This will lead to an instance of your Material. (If you pause the game and select the Cube - you should see Matial:Name (Instance) in the bottom of the Inspector. If there is just Material:Name shown - I´m wrong.)
To get rid of this Problem you can change the Material in the start of your script like:
void Start(){ renderer.sharedMaterial = YourUniqueMaterial }
Good Luck
Answer by FriedrichWessel · Nov 18, 2011 at 12:27 PM
Just for the Record: The Problem is that you create your Cube bei Instancing an prefab. This will lead to an instance of your Material. (If you pause the game and select the Cube - you should see Matial:Name (Instance) in the bottom of the Inspector. If there is just Material:Name shown - I´m wrong.)
To get rid of this Problem you can change the Material in the start of your script like:
void Start(){ renderer.sharedMaterial = YourUniqueMaterial }
Answer by Brain-_-Fail · May 22, 2020 at 05:52 AM
If you have a complex scene containing high polygon 3d models with a lot meshes that use a lot of different materials, the overall performance of your game will suffer. You can check out my tool on the unity asset store "Poly Few" that aims to solve this problem by allowing you to optimize high quality complex 3d scenes. With integrated features like mesh simplification, automatic LOD generation, mesh merging and material combining, you can greatly improve the performance of your game by lowering the Polygon Count, DrawCalls and SetPass calls with a few clicks and, without the need of writing even a single line of code.
Your answer
Follow this Question
Related Questions
Can I have multiple/alternate UV textures for one mesh in a single file? 0 Answers
2 materials/shaders 1 texture? 2 Answers
Batching problem when using multiple materials in one model 1 Answer
Can't figure out why 5 objects with the same material/texture are not batching.. 2 Answers
Which is the best inbuilt Unity transparent Shader to use for an iphone game. 1 Answer