Quick answer: Use the keyword’s Reference name (like _NIGHT_MODE_ON), not the display name, when calling EnableKeyword/DisableKeyword. Confirm the variant is included in the build via Always Included Shaders or a ShaderVariantCollection.
Here is how to fix Unity Shader Graph boolean keyword toggles that do nothing at runtime even though the editor preview switches correctly. The mismatch is usually the reference name, or the variant was stripped from the build.
The Symptom
You add a Boolean keyword in Shader Graph Blackboard. Toggle in editor preview — visual changes correctly. Call material.EnableKeyword("NightMode") at runtime — nothing changes.
What Causes This
Display name vs Reference. Display name is human-friendly; Reference is the actual keyword. Default reference is _KEYWORDNAME_ON with on/off suffix.
Variant stripped. Build pipeline removes unused variants. The runtime code references one not included.
Material vs Shader scope. Material keywords toggle per material. Shader.EnableKeyword toggles globally.
The Fix
Step 1: Find the keyword Reference name. Open the Shader Graph. Click your boolean keyword in the Blackboard. The Inspector shows Reference — that is the string to use in code, e.g., _NIGHT_MODE_ON.
Step 2: Toggle correctly.
using UnityEngine;
public class DayNightToggle : MonoBehaviour
{
[SerializeField] private Material mat;
public void SetNight(bool isNight)
{
if (isNight) mat.EnableKeyword("_NIGHT_MODE_ON");
else mat.DisableKeyword("_NIGHT_MODE_ON");
}
}
Step 3: For globals, use Shader.
Shader.EnableKeyword("_GLOBAL_NIGHT_ON");
All materials using the shader pick up the change. Use only when the toggle is truly project-wide.
Step 4: Include the variant in builds. Add the shader to Always Included Shaders. Build a ShaderVariantCollection capturing the on/off variants. Warm at app start so first toggle does not stutter.
Step 5: Verify with material.IsKeywordEnabled.
Debug.Log(mat.IsKeywordEnabled("_NIGHT_MODE_ON"));
Confirms the keyword state matches what you set.
“Reference name (with the _ON suffix). Material vs Shader scope. Variant included. The toggle works.”
Related Issues
For shader keyword limit, see Keyword Limit. For shader graph time, see Time Node in Build.
Reference name. Right scope. Variant present. Keywords toggle.