UI Canvas sorting with custom UI Shader

So, I’m currently optimizing the shaders for a project and I’m stuck when it comes to custom UI shaders.

I tried to write a Shader that basically does the same as the standard UI Shader from Unity but without all the special cases like masks and whatnot. So I came up with the Shader below.

Problem is: It breaks the Unity internal canvas z-sorting system somehow. So Images with a material attached with this shader seem to sort randomly and I don’t know why. Can somebody help me?

Here’s the code:

Shader "Mobile/UI/Default"
 {  
        Properties
        {
                [PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
        }
        SubShader
        {
                Tags 
                { 
						"Queue"="Geometry" 
						"RenderType"="Opaque"
						"ForceNoShadowCasting" = "True"
						"IgnoreProjector"="True"
                }                
                
                Pass
                {
                		Blend SrcAlpha OneMinusSrcAlpha
                		Cull Back

                                // I tried to edit these with no results
                		ZWrite Off
                		ZTest Off



                        CGPROGRAM
                        #pragma vertex vert
                        #pragma fragment frag

                        #pragma target 2.0
				        #pragma glsl_no_auto_normalization

            			#pragma only_renderers gles gles3 metal d3d11 glcore



                        sampler2D _MainTex;



                        struct VertexInput
                        {
                        	fixed4 position:POSITION;
                        	fixed2 uv:TEXCOORD0;
                        	fixed4 tintColor:COLOR;
                        };

                        struct VertexOutput
                        {
                        	fixed4 position : SV_POSITION;
                            fixed2 uv:TEXCOORD0;
                            fixed4 tintColor:COLOR;  
                        };

                        VertexOutput vert (VertexInput input)
                        {
                                VertexOutput output;
                                output.position = mul (UNITY_MATRIX_MVP, input.position);
                                output.uv = input.uv;
                                output.tintColor = input.tintColor;

                                return output;
                        }

                        fixed4 frag (VertexOutput input) : COLOR
                        {
                                fixed4 fragmentColor = tex2D (_MainTex, input.uv) * input.tintColor;

                                return fragmentColor;
                        }
                        ENDCG
                }
        }   
 }

Hey!
Open .mat file and remove this line:

m_CustomRenderQueue: #something#

Now it should work.

Don’t ask, just old Unity bug.