Dynamic Batching not compatible with UI elements? 5.6

I’m currently using the frame debugger and trying to achieve 3 batches in the following scene, as far as i understand it should be possible.

The hierarchy looks like this:

  • Main Canvas ( with RawImage as background, custom material, color (255, 255, 255, 255), raycast off)
  • Panel
  • Button ( RawImage as frame for raycast target, custom material, color (255, 255, 255, 0), raycast on)
  • Icon ( RawImage as button icon with some padding, custom material, color (255, 255, 255, 255), raycast off)
  • Button " same …
  • Icon " same …
  • Button …
  • Icon …
  • Button …
  • Icon …
  • Button …
  • Icon …

With this i’m getting 1 SetPass Call which i suppose is optimized but i’m getting 7 batches.

Looking at the frame debugger shows this:

background 1 batch (not in texture atlas)
5 transparent button raw images 1 batch only (no texture, not in atlas)
but here comes the thing, each icon raw image 1 batch individually (¿ignoring atlas?)

= 7 batches in total

Icons sprites settings:

Sprites are JPG 128x128.
Dynamic Batching is enabled in Player Settings.
Rendering Path Forward.
Canvas Screen Space - Overlay.
No lights in scene.

Material Shader:

Shader "SimpleUI" {
    Properties
    {
        [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
        _Color ("Tint", Color) = (1, 1, 1, 1)
    }

    SubShader
    {
        Tags {
            "Queue" = "Transparent"
            "IgnoreProjector" = "True"
            "RenderType" = "Transparent"
            "PreviewType" = "Plane"
            "CanUseSpriteAtlas" = "True"
        }

        Cull Off
        Lighting Off
        ZWrite Off
        ZTest [unity_GUIZTestMode]
        Blend SrcAlpha OneMinusSrcAlpha

        Pass
        {
        CGPROGRAM
            #pragma vertex vert
            #pragma fragment frag

            #include "UnityCG.cginc"
            #include "UnityUI.cginc"

              fixed4 _Color;
            fixed4 _TextureSampleAdd;
  
            struct appdata_t
            {
                float4 vertex   : POSITION;
                float4 color    : COLOR;
                float2 texcoord : TEXCOORD0;
            };

            struct v2f
            {
                float4 vertex   : SV_POSITION;
                fixed4 color    : COLOR;
                half2 texcoord  : TEXCOORD0;
                float4 worldPosition : TEXCOORD1;
            };
  
 

            v2f vert(appdata_t IN)
            {
                v2f OUT;
                OUT.worldPosition = IN.vertex;
                OUT.vertex = UnityObjectToClipPos(OUT.worldPosition);

                OUT.texcoord = IN.texcoord;
      
                #ifdef UNITY_HALF_TEXEL_OFFSET
                OUT.vertex.xy += (_ScreenParams.zw-1.0)*float2(-1,1);
                #endif
      
                OUT.color = IN.color * _Color;
                return OUT;
            }

            sampler2D _MainTex;
            fixed4 frag(v2f IN) : SV_Target
            {
                return (tex2D(_MainTex, IN.texcoord) + _TextureSampleAdd) * IN.color;
            }
        ENDCG
        }
    }
}

EDIT:

Interestingly using the same sprite ( part of the atlas ) in all icons raw images is getting me the desired 3 batches in the exposed scene.

I’m lost :eyes:, why is not working with separated sprites in the same atlas?

Alright this Dynamic Batching seems to only work with sprite renderes, which lets me wondering is this technique not aplicable to UI elements?

If so, do i have alternatives?