# SetKeyword(in LocalKeyword, bool)

> Sets the state of a local shader keyword for this material.

## Definition

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

## SetKeyword(LocalKeyword, bool)

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

### Parameters

**** (\[LocalKeyword]\(/engine/6000.5/script-reference/unityengine/rendering/localkeyword)): The [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.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.5/script-reference/unityengine/rendering/localkeyword.md) and [global shader keywords](/engine/6000.5/script-reference/unityengine/rendering/globalkeyword.md) and how they interact, see [Using shader keywords with C# scripts](/engine/6000.5/manual/materials-and-shaders/shaders/writing-custom/shader-writing/sl-multiple-program-variants/shader-keywords-scripts.md).

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

If the [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md) does not exist in the [Shader.keywordSpace](/engine/6000.5/script-reference/unityengine/shader/keywordspace.md) for the shader that this material uses, this function has no effect.

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

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

public class MaterialKeywordExample : MonoBehaviour
{
    public Material material;
    private LocalKeyword exampleFeatureKeyword;

    void Start()
    {
        // Get the instance of the Shader class that this material uses
        var shader = material.shader;

        // Create and cache the LocalKeyword
        exampleFeatureKeyword = new LocalKeyword(shader, "EXAMPLE_FEATURE_ON");
    }

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

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

Additional Resources: Shader variants and keywords, [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md), [GlobalKeyword](/engine/6000.5/script-reference/unityengine/rendering/globalkeyword.md), [Material.EnableKeyword](/engine/6000.5/script-reference/unityengine/material/enablekeyword.md), [Material.DisableKeyword](/engine/6000.5/script-reference/unityengine/material/disablekeyword.md), [Shader.keywordSpace](/engine/6000.5/script-reference/unityengine/shader/keywordspace.md), [Material.IsKeywordEnabled](/engine/6000.5/script-reference/unityengine/material/iskeywordenabled.md), [Material.enabledKeywords](/engine/6000.5/script-reference/unityengine/material/enabledkeywords.md), [Material.shaderKeywords](/engine/6000.5/script-reference/unityengine/material/shaderkeywords.md).
