Custom Shadows not showing up in build

So, I’ve been working on a project with a custom toon shader using the Universal render pipeline. Everything is working well except that when I build the game multiple effects within the shader graph stop working.

The most noticeable is the cast shadows disappearing. I am using a custom hlsl function within the unlit shadergraph to get the main light information. It works fine in editor but something with the shadow attenuation isn’t working in build. Shadows on URP default materials are showing up and other lit shadergraph materials, it is only my custom toon shaded materials that are encountering this issue which leads me to believe its either a bug with custom functions in shadergraph or something I have messed up. My custom function for intercepting SSAO is also not appearing in the build. I am assuming for similar reasons, but I can’t find out what those are for the life of me. I suspect it’s something to do with the multi-compile keywords but I’m not really well versed in shader code enough to say for sure. Any help would be appreciated.

Here are the shadows in game vs in build:

Here is my code for the custom CalculateMainLight function. The custom light was taken from this video:

#ifndef CUSTOM_LIGHTING_INCLUDED
#define CUSTOM_LIGHTING_INCLUDED

#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile _ _SHADOWS_SOFT

void CalculateMainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, out half DistanceAtten, out half ShadowAtten) {
#ifdef SHADERGRAPH_PREVIEW
Direction = float3(0.5, 0.5, 0);
Color = 1;
DistanceAtten = 1;
ShadowAtten = 1;
#else
#if SHADOWS_SCREEN
half4 clipPos = TransformWorldToHClip(WorldPos);
half4 shadowCoord = ComputeScreenPos(clipPos);
#else
half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
#endif
Light mainLight = GetMainLight(shadowCoord);
Direction = mainLight.direction;
Color = mainLight.color;
DistanceAtten = mainLight.distanceAttenuation;
ShadowAtten = mainLight.shadowAttenuation;
#endif

}

Hey ! Did you ever find a solution to this ? I’ve been having the exact same issue, following a tutorial from the exact same channel. everything working fine in editor, and then not working on Build.

Edit : for anyone having the issue, found a solution from this thread

they changed the format of the keywords so the solution is to write it like this in the .hlsl file

Old keywords variant:
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
New variant:
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN

Try to disable shader variant stripping in the project settings to see whether that is the cause. If yes, you’ll have to create a shader variant collection to avoid that used variants are getting stripped. Alternatively, you could also create a few dummy materials with the used variants.
This happens when you have variants that are only referenced in code. In that case, Unity doesn’t find a reference to the variant and strips it.

I did eventually solve it, from what I remember it was the fact that I was using multi_compile instead of shader_feature on the _MAIN_LIGHT_SHADOWS

here’s the updated script

#ifndef CUSTOM_LIGHTING_INCLUDED
#define CUSTOM_LIGHTING_INCLUDED

#pragma shader_feature _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
#pragma multi_compile _ _SHADOWS_SOFT

void CalculateMainLight_float(float3 WorldPos, out float3 Direction, out float3 Color, out half DistanceAtten, out half ShadowAtten) {
#ifdef SHADERGRAPH_PREVIEW
    Direction = float3(0.5, 0.5, 0);
    Color = 1;
    DistanceAtten = 1;
    ShadowAtten = 1;
#else
    #if SHADOWS_SCREEN
        half4 clipPos = TransformWorldToHClip(WorldPos);
        half4 shadowCoord = ComputeScreenPos(clipPos);
    #else
        half4 shadowCoord = TransformWorldToShadowCoord(WorldPos);
    #endif
    Light mainLight = GetMainLight(shadowCoord);
    Direction = mainLight.direction;
    Color = mainLight.color;
    DistanceAtten = mainLight.distanceAttenuation;
    ShadowAtten = mainLight.shadowAttenuation;
#endif

}

its not actually c# but I don’t know how to include an hlsl snippets

Thanks ! I got it to work as said in my edit, but i’ll check your solutions too later just in case