• RuntimesUnityBugs
  • Batches Increase If I Have Duplicates Animations Even With Same Material

I am encountering an issue where the batch count increases with each duplicate animation or gameobject, despite using a single material. I aim to use this setup for animations and various skins, such as vegetation and trees, within a single material file (not sure if this is viable in the first place).

How can I resolve this issue to ensure the batch count does not increase with duplicates?

I have attached an example of the problem for reference.


Related Discussions
...

The issue you're encountering with increased batch counts despite using a single material is likely due to the way Unity handles dynamic batching and material instances. Here are some steps and considerations to help resolve this issue:

  1. Dynamic Batching and Material Instances:

    • Ensure that you are not inadvertently creating new material instances. Using MeshRenderer.material can create duplicates. Instead, use MeshRenderer.sharedMaterial to avoid this.
    • Refer to the documentation on Changing Materials Per Instance to ensure you are handling materials correctly.
  2. Draw Order and Atlas Textures:

    • If your draw order requires switching between different textures, this can increase the batch count. Group attachments according to atlas textures to minimize material switches. Refer to the Material Switching and Draw Calls documentation for more details.
    • Consider repacking your skins to a single atlas texture if possible. This can help reduce the number of draw calls. More information can be found in the Combining Skins section.
  3. Render Pipeline Considerations:

    • If you are using Unity's Universal Render Pipeline (URP), aggressive batching might be causing issues. Enabling the Fix Draw Order parameter in the SkeletonRenderer inspector or adding a SortingGroup component to your GameObject can help. More details are available in the Setting Advanced Parameters section.
  4. General Optimization Tips:

    • Ensure that all your animations and skins are using the same material and texture to benefit from dynamic batching.
    • Avoid using compressed textures if they prevent you from repacking skins into a single atlas texture.

By following these steps, you should be able to reduce the batch count and optimize your setup for animations and various skins.

@iammirrr If you're using URP, please note that the SRP batcher is separate from the normal batcher, and these are mutually exclusive. You should be able to find quite a few threads here on the forum that explain it a bit more in detail, like this one:
https://esotericsoftware.com/forum/d/26150-urp-batching

Im not really sure I turned on the dynamic batching this seems to solve the problem not sure if this is actually the correct solution.

  • Harald ответили на это сообщение.

    iammirrr Im not really sure I turned on the dynamic batching this seems to solve the problem not sure if this is actually the correct solution.

    I'm not sure what you mean by that. Enabling Dynamic Batching is the correct solution if you want to enable batching on non-static objects (skeletons are non-static).

    If you're using URP, then you have the additional (mutually-excusive) option to use the SRP batcher instead.