I have to disable a keyword before enabling another one, why?

Can anyone help me with this one? I know there is scoring system behind how Unity select matching shaders, but I really can’t figure out myself how that works under this situation.

Here is my key words set: _EMISSION _FOGENABLE _REALTIME_LIGHT_ENABLE _REFLECT_OFF _SOFTOUTLINE_ON _MY_FEATURE

To enable the keyword _MY_FEATURE at runtime in a build, I have to disable _FOGENABLE. Why is this happening? (I don’t have to disable _FOGENABLE in editor mode tho)

How do you declare those keywords in the shader?

Sure. The effect of _MY_FEATURE is enabled if I manually disable _FOGENABLE

Working:

            var mat = GetComponent<MeshRenderer>().sharedMaterial;
            mat.EnableKeyword("_MY_FEATURE");
            mat.DisableKeyword("_FOGENABLE");

Not Working:

            var mat = GetComponent<MeshRenderer>().sharedMaterial;
            mat.EnableKeyword("_MY_FEATURE");

Shader looks like this:

            HLSLPROGRAM
            #include "../Library/Assets.hlsl"
            #pragma target 3.5
            #pragma prefer_hlslcc gles
            #pragma exclude_renderers d3d11_9x
            #pragma fragmentoption ARB_precision_hint_fastest
            #pragma skip_variants POINT POINT_COOKIE SHADOWS_SCREEN VERTEXLIGHT_ON LIGHTPROBE_SH SHADOWS_CUBE LINEAR_FOG
          
            #pragma multi_compile __ _DISABLE_FOG
            #pragma multi_compile __ LIGHTMAP_ON
            #pragma multi_compile __ _HEIGHTFOG_ON
            #pragma multi_compile _SOFT_SHADOW_16
            #pragma multi_compile __ _CASCADE_SHADOWMAP_ON _STANDARD_SHADOWMAP_ON

            #pragma shader_feature _REFLECT_OFF _REFLECT_CUBE _REFLECT_MIRROR
            #pragma shader_feature _RECEIVE_SHADOWS
            #pragma shader_feature _NORMALMAP
            #pragma shader_feature _RAMPMAP
            #pragma shader_feature _EMISSION
            #pragma shader_feature _FOGENABLE
            #pragma shader_feature _REALTIME_LIGHT_ENABLE
            #pragma shader_feature METALLIC_SPECGLOSS_MAP 
#pragma shader_feature _ _MY_FEATURE
            #pragma vertex AssetsPassVertex
            #pragma fragment AssetsPassFragment
            ENDHLSL

Do you have any material that has this setup (both _FOGENABLE and _MY_FEATURE enabled)?
Shader features provide a way to reduce the amount of variants compiled for the player that is based on material usage. If there is no material that has both enabled referenced in the scenes that go to the build, the variants will not be there, so it won’t work.
You need to either include such a material or change to use multi_compile. The latter will include all possible variant combinations, but this means it has more variants to compile.
Check Unity - Manual: Declaring and using shader keywords in HLSL for more info.