Custom URP shader turning pink in build

My shader works completely fine in the editor but once its compiled it turns pink. I’m assuming its just being stripped from the build because in the console I have it print the shader compile logs and it shows this result

my shader variants not being compiled

and this is what it looks like in editor

and in build

I’ve looked through many of peoples posts that have experienced a similar bug. I’ve included the shader in “Always Included Shaders”, “Preloaded Shaders”, Preloaded Assets" and the Resource folder to no success. I’ve also made a material with this shader and included a game object that uses this material in the main menu scene (as depicted in the screenshots).
I’ve included all API targets in the shader asset and only skip unused variants but as you can see it says both variants are included

But in the previous screen shot at the top you can see that both of the variants aren’t made.

I’ve tried just about everything I’ve seen on the forums and still cant fix the issue PLS let me know if you have the solution.

Also my shader code just incase its a code issue

Shader "Custom/VolumeLit"
{
    Properties
    {
   
        /*[MainTexture]*/_BaseMap ("Texture", 2D) = "white" {}
        //_Gain ("Gain", Float) = 1.5
        /*[MainColor]*/_Color ("Color", Color) = (1,1,1,1)
        //_EdgeColor ("Edge Color", Color) = (0,0,0,1)
   
    }
    HLSLINCLUDE
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
        #pragma multi_compile  _ADDITIONAL_LIGHTS_VERTEX
        #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
        struct appdata
        {
       
            float4 vertex : POSITION;
       
            float2 uv : TEXCOORD0;
            float3 normal     : NORMAL;
            float4 tangent    : TANGENT;
       
        };
        struct v2g
        {
            float2 uv : TEXCOORD0;
            float4 vertex : SV_POSITION;
            float3 normal : POSITION1;
            float4 world : TEXCOORD2;
        };
        struct g2f
        {
            float2 uv : TEXCOORD0;
            float4 vertex : SV_POSITION;
            float3 bary : TEXCOORD1;
            float3 normal : POSITION1;
            float4 world : TEXCOORD2;
        };
        TEXTURE2D(_BaseMap);
        SAMPLER(sampler_BaseMap);
   
        CBUFFER_START(UnityPerMaterial)
        float4 _BaseMap_ST;
        //float _Gain;
        float4 _Color;
        //float4 _EdgeColor;
        CBUFFER_END
        StructuredBuffer<uint> _LightBuffer;
        int _CustLightProbeCount;
        float4 _LightProbeStart;
        float4 _LightProbeVol;
        v2g vert (appdata v)
        {
            v2g o;
       
            o.world = mul(unity_ObjectToWorld, v.vertex);
            o.vertex = TransformObjectToHClip(v.vertex.xyz);
            o.uv = TRANSFORM_TEX(v.uv, _BaseMap);
            o.normal = TransformObjectToWorldNormal(v.normal);
       
            return o;
        }
   
        /*float edgeFactor(float3 bary)
        {
            float3 d = fwidth(bary);
            float3 a3 = smoothstep(float3(0, 0, 0), _Gain * d, bary);
            return min(min(a3.x, a3.y), a3.z);
        }*/
        int getindex(int x, int y, int z)
        {
            //x = clamp(x, 0, _LightProbeVol.x);
            //y = clamp(y, 0, _LightProbeVol.y);
            //z = clamp(z, 0, _LightProbeVol.z);
            if (x >= 0 && y >= 0 && z >= 0 && x < _LightProbeVol.x && y < _LightProbeVol.y && z < _LightProbeVol.z)
                return (y * _LightProbeVol.x * _LightProbeVol.z) + (z * _LightProbeVol.x) + x;
            else
                return -1;
        }
        half4 getcolor(int index)
        {
            if (index == -1)
                return half4(0,0,0,0);
            uint r = asint(_LightBuffer[index] & 0x000000FF);
            uint g = asint(_LightBuffer[index] & 0x0000FF00) >> 8;
            uint b = asint(_LightBuffer[index] & 0x00FF0000) >> 16;
            half4 color = half4(r * 0.003921,g * 0.003921,b * 0.003921, 1);
            return color;
        }
        float3 getdirection(int index)
        {
            int pitchi = asint(_LightBuffer[index] & 0x0F000000) >> 24;
            int yawi = asint(_LightBuffer[index] & 0xF0000000) >> 28;
            float pitch = -radians(-(pitchi * 24));
            float yaw = radians(-(yawi * 24) - 90);
            float3 dir = float3(cos(pitch)*cos(yaw), sin(pitch), cos(pitch) * sin(yaw));
            return dir;
        }
   
        half4 frag (v2g i) : SV_Target
        {
       
            half4 ogcol = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, i.uv) * _Color; // tex2D(_MainTex, i.uv)
            half4 col = half4(0,0,0,0);
            if (_CustLightProbeCount > 0)
            {
                //float t = fwidth(i.bary);//edgeFactor(i.bary);
                //Light mainLight = GetMainLight();
                const float maxdistance = 2.0;
                const float xzstepdist = 1.205464;
                const float ystepdist = 2.410929;
                const float xzstepdisthalf = 0.602732;
                const float ystepdisthalf = 1.205464;
                const float xzscale = 0.8295560; //  (1.205464 = meterscale * 64 because the xz index is stepped by 64 quake units then scaled for unity)  1 / 1.205464 doing this bec i think * is faster than /
                const float yscale  = 0.4147778; // (2.410929 = meterscale * 128 because the y index is stepped by 128 quake units then scaled for unity) 1 / 2.410929
                float3 delta = i.world.xyz - _LightProbeStart.xyz;
                int xind = floor(delta.x * xzscale);
                int zind = floor(delta.z * xzscale);
                int yind = floor(delta.y * yscale);
                //return normalize(half4(xind, yind, zind, 1));
                int index = getindex(xind, yind, zind);
                if (index != -1)
                {
                    float3 lightpos = (_LightProbeStart.xyz + float3(xind * xzstepdist, yind * ystepdist, zind * xzstepdist));
                    //lightpos.x += xzstepdisthalf;
                    //lightpos.z += xzstepdisthalf;
                    //lightpos.y += ystepdisthalf;
                    delta = i.world.xyz - lightpos;
                    delta.x *= 0.82955608;
                    delta.z *= 0.82955608;
                    delta.y *=    0.41477787;
                    int index1 = getindex(xind + 1, yind, zind);
                    int index2 = getindex(xind, yind + 1, zind);
                    int index3 = getindex(xind + 1, yind + 1, zind);
                    int index4 = getindex(xind, yind, zind + 1);
                    int index5 = getindex(xind + 1, yind, zind + 1);
                    int index6 = getindex(xind, yind + 1, zind + 1);
                    int index7 = getindex(xind + 1, yind + 1, zind + 1);
                    half4 c000 = getcolor(index);
                    half4 c100 = getcolor(index1);
                    half4 c010 = getcolor(index2);
                    half4 c110 = getcolor(index3);
                    half4 c001 = getcolor(index4);
                    half4 c101 = getcolor(index5);
                    half4 c011 = getcolor(index6);
                    half4 c111 = getcolor(index7);
                    half4 color = (1 - delta.x) * (1 - delta.y) * (1 - delta.z) * c000 +
                        delta.x * (1 - delta.y) * (1 - delta.z) * c100 +
                        (1 - delta.x) * delta.y * (1 - delta.z) * c010 +
                        delta.x * delta.y * (1 - delta.z) * c110 +
                        (1 - delta.x) * (1 - delta.y) * delta.z * c001 +
                        delta.x * (1 - delta.y) * delta.z * c101 +
                        (1 - delta.x) * delta.y * delta.z * c011 +
                        delta.x * delta.y * delta.z * c111;
                    //return  color;
                    float3 c0002 = getdirection(index);
                    float3 c1002 = getdirection(index1);
                    float3 c0102 = getdirection(index2);
                    float3 c1102 = getdirection(index3);
                    float3 c0012 = getdirection(index4);
                    float3 c1012 = getdirection(index5);
                    float3 c0112 = getdirection(index6);
                    float3 c1112 = getdirection(index7);
                    float3 dir = (1 - delta.x) * (1 - delta.y) * (1 - delta.z) * c0002 +
                        delta.x * (1 - delta.y) * (1 - delta.z) * c1002 +
                        (1 - delta.x) * delta.y * (1 - delta.z) * c0102 +
                        delta.x * delta.y * (1 - delta.z) * c1102 +
                        (1 - delta.x) * (1 - delta.y) * delta.z * c0012 +
                        delta.x * (1 - delta.y) * delta.z * c1012 +
                        (1 - delta.x) * delta.y * delta.z * c0112 +
                        delta.x * delta.y * delta.z * c1112;
                    half nl = dot(i.normal, dir);
                    if (nl > 0)
                        nl = 1;
                    else
                        nl = 1 + nl;
           
                    half4 diff = nl * color;
                    diff.w = 1;
                    diff = max(0, diff);
                    diff *= ogcol;
               
                    col += diff;
                    col += ogcol * half4(VertexLighting(i.world.xyz, i.normal), 1);        
                }
            }
       
            return col;
        }
    ENDHLSL
    SubShader
    {
        Tags{"RenderType" = "Opaque" "RenderPipeline" = "UniversalPipeline"}
        Pass
        {
            Tags{"LightMode" = "UniversalForward"}
            HLSLPROGRAM
            #pragma target 2.0
            #pragma multi_compile_instancing
            #pragma vertex vert
            #pragma fragment frag
   
            ENDHLSL
        }
    }
}

Edit:

Changing #pragma multi_compile _ADDITIONAL_LIGHTS_VERTEX
to
#define _ADDITIONAL_LIGHTS_VERTEX

seems to have worked

I was having the same issue and doing all this

I’ve looked through many of peoples posts that have experienced a similar bug. I’ve included the shader in “Always Included Shaders”, “Preloaded Shaders”, Preloaded Assets" and the Resource folder to no success. I’ve also made a material with this shader and included a game object that uses this material in the main menu scene (as depicted in the screenshots).
I’ve included all API targets in the shader asset and only skip unused variants but as you can see it says both variants are included

Also didnt work. BUT taking a look at your code I noticed had the wrong tag. "“RenderPipeline”=“UniversalRenderPipeline” instead of "“RenderPipeline”=“UniversalPipeline

Changing that made it work in the build. So for anyone having similar issues in build only, the problem is most likely a wrong tag or definition in the shader.

Dude I can’t say thank you enough. I had a similar error and only you spotted out to check the actual tag for shaders among my 2 hours searching with Google. I changed it in my shader script and then it fixed the error. Thank you again.

Hey thank you, that worked for me as well. I changed From “RenderPipeline”=“UniversalRenderPipeline" To "“RenderPipeline”=“UniversalPipeline” it did work for me. i have been writing custom Toon Shader with Outline Unity 6000.2.5f1 below i will leave a Code, it is fully working now, if anyone needs it, just copy paste

Again WulfB thank you )

Shader "URP/ToonWithOutline"
{
    Properties
    {
        _BaseMap ("Base Texture", 2D) = "white" {}
        _BaseColor ("Base Color", Color) = (1,1,1,1)

        _ShadowStrength ("Shadow Strength", Range(0,1)) = 0.5
        _HighlightStrength ("Highlight Strength", Range(0,1)) = 0.5
        _ShadowThreshold ("Shadow Threshold", Range(0,1)) = 0.33
        _HighlightThreshold ("Highlight Threshold", Range(0,1)) = 0.66
        [Toggle(_ALPHATEST_ON)] _IsAlphaClipOn ("Enable Alpha Clip", Float) = 0
        _Cutoff ("Alpha Cutoff", Range(0,1)) = 0.5

        [Toggle(_DOUBLE_SIDED)] _DoubleSided ("Double Sided", Float) = 0
        [Toggle(_USE_OUTLINE)] _UseOutline ("Use Outline", Float) = 1

        _OutlineColor ("Outline Color", Color) = (0,0,0,1)
        _OutlineThickness ("Outline Thickness", Range(0,0.1)) = 0.02
    }

    SubShader
    {
        Tags { "RenderPipeline"="UniversalPipeline" "RenderType"="Opaque" }
        LOD 200

        // ---------- PASS 1: Toon Lit ----------
        Pass
        {
            Name "ToonLit"
            Tags { "LightMode"="UniversalForward" }

            // Dynamically switch culling
            Cull [_CullMode]

            HLSLPROGRAM
            #pragma target 3.0
            #pragma multi_compile _ _MAIN_LIGHT_SHADOWS
            #pragma multi_compile _ _ADDITIONAL_LIGHTS
            #pragma multi_compile _ _ADDITIONAL_LIGHT_SHADOWS
            #pragma shader_feature_local _ALPHATEST_ON
            #pragma vertex vert
            #pragma fragment frag

    

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"

            TEXTURE2D(_BaseMap);
            SAMPLER(sampler_BaseMap);

            float4 _BaseColor;
            float _ShadowStrength;
            float _HighlightStrength;
            float _ShadowThreshold;
            float _HighlightThreshold;
            float _Cutoff;

            struct Attributes
            {
                float4 positionOS : POSITION;
                float3 normalOS   : NORMAL;
                float2 uv         : TEXCOORD0;
            };

            struct Varyings
            {
                float4 positionCS : SV_POSITION;
                float3 normalWS   : TEXCOORD0;
                float3 positionWS : TEXCOORD1;
                float2 uv         : TEXCOORD2;
            };

            Varyings vert(Attributes IN)
            {
                Varyings OUT;
                OUT.positionCS = TransformObjectToHClip(IN.positionOS.xyz);
                OUT.normalWS   = normalize(TransformObjectToWorldNormal(IN.normalOS));
                OUT.positionWS = TransformObjectToWorld(IN.positionOS).xyz;
                OUT.uv         = IN.uv;
                return OUT;
            }

            static float3 ToonShade(float3 normal, float3 lightDir, float3 lightColor, float3 baseColor,
                                    float shadowStrength, float highlightStrength,
                                    float shadowThreshold, float highlightThreshold)
            {
                float NdotL = saturate(dot(normal, lightDir));
                float3 shadowCol    = baseColor * shadowStrength;
                float3 highlightCol = saturate(baseColor + highlightStrength);

                float shadowMask    = 1.0 - step(shadowThreshold, NdotL);
                float highlightMask = step(highlightThreshold, NdotL);
                float baseMask      = 1.0 - shadowMask - highlightMask;

                float3 toonColor = shadowCol * shadowMask +
                                   baseColor * baseMask +
                                   highlightCol * highlightMask;

                return toonColor * lightColor;
            }

            half4 frag(Varyings IN) : SV_Target
            {
                // Sample texture
                float4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, IN.uv);
                float alpha = texColor.a * _BaseColor.a;

                // Alpha clipping
                #ifdef _ALPHATEST_ON
                    clip(alpha - _Cutoff);
                #endif

                float3 baseCol = texColor.rgb * _BaseColor.rgb;
                float3 normal = normalize(IN.normalWS);
                float3 finalColor = 0;

                // Main light
                Light mainLight = GetMainLight();
                finalColor += ToonShade(normal, mainLight.direction, mainLight.color.rgb, baseCol,
                                        _ShadowStrength, _HighlightStrength, _ShadowThreshold, _HighlightThreshold);

                // Additional lights
                int lightCount = GetAdditionalLightsCount();
                for (int i = 0; i < lightCount; i++)
                {
                    Light addLight = GetAdditionalLight((uint)i, IN.positionWS);
                    float3 addLightColor = addLight.color.rgb * addLight.distanceAttenuation;
                    finalColor += ToonShade(normal, addLight.direction, addLightColor, baseCol,
                                            _ShadowStrength, _HighlightStrength, _ShadowThreshold, _HighlightThreshold);
                }

                return half4(finalColor, alpha);
            }
            ENDHLSL
        }

        // ---------- PASS 2: Outline ----------
        Pass
        {
            Name "Outline"
            Tags { "LightMode"="SRPDefaultUnlit" }
            Cull Front

            HLSLPROGRAM
            #pragma target 3.0
            #pragma multi_compile _ _USE_OUTLINE

            #pragma vertex vert
            #pragma fragment frag

            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
            #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"

            float4 _OutlineColor;
            float _OutlineThickness;

            // Property toggle:
            // [Toggle(_USE_OUTLINE)] _UseOutline ("Use Outline", Float) = 1

            struct Attributes2
            {
                float4 positionOS : POSITION;
                float3 normalOS   : NORMAL;
            };

            struct Varyings2
            {
                float4 positionCS : SV_POSITION;
            };

            Varyings2 vert(Attributes2 IN)
            {
                Varyings2 OUT;

                #ifdef _USE_OUTLINE
                    float3 normWS = TransformObjectToWorldNormal(IN.normalOS);
                    float3 posWS  = TransformObjectToWorld(IN.positionOS.xyz).xyz;
                    posWS += normWS * _OutlineThickness;
                    OUT.positionCS = TransformWorldToHClip(posWS);
                #else
                    // Push offscreen if outline disabled
                    OUT.positionCS = float4(0, 0, 0, 0);
                #endif

                return OUT;
            }

            half4 frag(Varyings2 IN) : SV_Target
            {
                #ifdef _USE_OUTLINE
                    return _OutlineColor;
                #else
                    return half4(0, 0, 0, 0); // ✅ Always return something
                #endif
            }
            ENDHLSL
        }
    }
}