# SetKeyword(in GlobalKeyword, bool)

> Sets the state of a global shader keyword.

## Definition

* **Type:** Method
* **Namespace:** [UnityEngine](/engine/6000.0/script-reference/unityengine.md)
* **Assembly:** UnityEngine.CoreModule

## SetKeyword(GlobalKeyword, bool)

```csharp
public static void SetKeyword(in GlobalKeyword keyword, bool value)
```

### Parameters

**** (\[GlobalKeyword]\(/engine/6000.0/script-reference/unityengine/rendering/globalkeyword)): The [GlobalKeyword](/engine/6000.0/script-reference/unityengine/rendering/globalkeyword.md) to enable or disable.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): The desired keyword state.

### Remarks

Shader keywords determine which shader variants Unity uses. For information on working with [local shader keywords](/engine/6000.0/script-reference/unityengine/rendering/localkeyword.md) and [global shader keywords](/engine/6000.0/script-reference/unityengine/rendering/globalkeyword.md) and how they interact, see [Using shader keywords with C# scripts](/engine/6000.0/manual/materials-and-shaders/shaders/writing-custom/shader-writing/sl-multiple-program-variants/shader-keywords-scripts.md).

When `value` is `true`, this function calls [Shader.EnableKeyword](/engine/6000.0/script-reference/unityengine/shader/enablekeyword.md). Otherwise, it calls [Shader.DisableKeyword](/engine/6000.0/script-reference/unityengine/shader/disablekeyword.md).

The following example creates and caches a `GlobalKeyword`, and provides a function to toggle its state.

```csharp
using UnityEngine;
using UnityEngine.Rendering;

public class GlobalKeywordExample : MonoBehaviour
{
    private GlobalKeyword exampleFeatureKeyword;

    private void Start()
    {
        // Create and cache the GlobalKeyword
        exampleFeatureKeyword = GlobalKeyword.Create("EXAMPLE_FEATURE_ON");
    }

    public void ToggleExampleFeature()
    {
        // Get the current state of the global keyword
        bool state = Shader.IsKeywordEnabled(exampleFeatureKeyword);

        // Toggle the state
        Shader.SetKeyword(exampleFeatureKeyword, !state);
    }
}
```

Additional Resources: Shader variants and keywords, [LocalKeyword](/engine/6000.0/script-reference/unityengine/rendering/localkeyword.md), [GlobalKeyword](/engine/6000.0/script-reference/unityengine/rendering/globalkeyword.md), [Shader.EnableKeyword](/engine/6000.0/script-reference/unityengine/shader/enablekeyword.md), [Shader.DisableKeyword](/engine/6000.0/script-reference/unityengine/shader/disablekeyword.md), [Shader.IsKeywordEnabled](/engine/6000.0/script-reference/unityengine/shader/iskeywordenabled.md), [Shader.enabledGlobalKeywords](/engine/6000.0/script-reference/unityengine/shader/enabledglobalkeywords.md), [Shader.globalKeywords](/engine/6000.0/script-reference/unityengine/shader/globalkeywords.md).
