I have only 20 materials in my game (19 are made with textures atlas). But the Setpass call is 72. I don't understand why. I want to know how to decrease the number of SetPass call.

This is a brief summary about the game:
Houses vertex attributes : from 43 to 270. They are low poly houses. Props too.
No normal maps. Only diffuse and ambient occlusion maps. Only the Playable character has his own texture. There 45 houses models. I have 19 textures atlas.
In the game, some houses are assembled to formed another house (modular houses). And I assembled 10 to 18 houses to form a BLOC (a piece of town).
For all the gameObects, SHADER is Universal Render Pipeline. I didn't edit anything, I use the default properties.
In the game, Bloc of houses are put together 3 by 3 and randomly to form town like (SUBWAY SURFER)
In Unity playmode :
Tris : 54.9k
Verts: 80k
Batches : 466
Saved by batching : 0
Shadow caster: 0
Visible Skinned meshes: 1

  • \$\begingroup\$ There are a lot of reasons why you could happen and you don't provide much information. Just a wild guess: Are you modifying material properties with code? Like color, for example? \$\endgroup\$ – Philipp Jul 9 '20 at 8:53
  • \$\begingroup\$ No, I don't modify material properties with code. I don't have transparent shader. \$\endgroup\$ – Achie1 Jul 9 '20 at 9:04
  • 2
    \$\begingroup\$ As Philipp says, we'll need more information about how you've set up your project to be able to help you here. It could be you have more models/vertex data than will fit into a single batch even with shared materials, or you're using materials with batching disabled, or your models are not static so the engine can't use static batching, or you've inadvertently copied the materials somewhere, or you have many lights, or you're using a lot of skinned meshes which don't batch, or you're rendering in a queue that uses sorting, or you have multiple cameras, or or or... \$\endgroup\$ – DMGregory Jul 9 '20 at 10:34
  • \$\begingroup\$ It's a 3D platform game, an infinite runner game. I have only one light (the directional light), one camera. I made many blocs of house. I make them Prefab. Each bloc contains 10 or 18 houses and some props. Each house has no more than 300 vertices. I use texture atlas (1 texture for 6 houses). So platforms are generated procedurally. But houses and props are not Static. I don't use Skinned mesh. I don't render in a queue that uses sorting. Nb: in the game Stats : Tris : 49 k Verts : 71k Batches : 394 Saved by batching : 0 \$\endgroup\$ – Achie1 Jul 9 '20 at 11:43
  • 1
    \$\begingroup\$ Bear in mind that the number of draw calls isn't just separate materials, but each material on each object. That is, even if two objects have the same material, they will be separate draw calls. Unity attempts to optimize around this through batching meshes, but your game stats show no batching is happening. Thus, your issue really boils down to "why isn't it batching?" \$\endgroup\$ – jhocking Jul 10 '20 at 14:10

This is something that is easy to diagnose yourself. Just turn off objects in your scene (uncheck the box next to their name in the inspector to deactivate their GameObject) one at a time and watch how the stats change. If the SetPass calls drop off a lot after disabling a particular object, you've found your culprit. Then you just need to investigate the configuration of that object.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.