# IsKeywordEnabled

> Checks whether a local shader keyword is enabled for this material.

## Definition

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

## IsKeywordEnabled(string)

Checks whether a local shader keyword is enabled for this material.

```csharp
public bool IsKeywordEnabled(string keyword)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md) to check.

### Returns

| Type                                                          | Description                                                                                                                                                 |
| ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Returns `true` if a [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md) with the given name is enabled for this material. |

### 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).

If you pass in a [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md) and it 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 returns `false`. If you pass a string and a [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md) with that `name` 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 returns `false`.

The version of this function that takes a string as a parameter is slower than the version that takes a [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md). If you call this function more than once, it's best practice to create a [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md) struct, cache it, and use that.

**Note:** A `LocalKeyword` is specific to a single [Shader](/engine/6000.5/script-reference/unityengine/shader.md) or [ComputeShader](/engine/6000.5/script-reference/unityengine/computeshader.md) instance. You cannot use it with other [Shader](/engine/6000.5/script-reference/unityengine/shader.md) or [ComputeShader](/engine/6000.5/script-reference/unityengine/computeshader.md) instances, even if they declare keywords with the same name.

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

// This example iterates over the local shader keywords in the local
// keyword space for a graphics shader. It determines whether each
// keyword is overridden by a global shader keyword and prints its
// state.
public class KeywordExample : MonoBehaviour
{
    public Material material;

    void Start()
    {
        CheckShaderKeywordState();
    }

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

        // Get all the local keywords that affect the Shader
        LocalKeywordSpace keywordSpace = shader.keywordSpace;

        // Iterate over the local keywords
        foreach (LocalKeyword localKeyword in keywordSpace.keywords)
        {
            // If the local keyword is overridable,
            // and a global keyword with the same name exists and is enabled,
            // then Unity uses the global keyword state
            if (localKeyword.isOverridable && Shader.IsKeywordEnabled(localKeyword.name))
            {
                Debug.Log("Local keyword with name of " + localKeyword.name + " is overridden by a global keyword, and is enabled");
            }
            // Otherwise, Unity uses the local keyword state
            else
            {
                string state = material.IsKeywordEnabled(localKeyword) ? "enabled" : "disabled";
                Debug.Log("Local keyword with name of " + localKeyword.name + " is " + 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), [Material.SetKeyword](/engine/6000.5/script-reference/unityengine/material/setkeyword.md), [Shader.keywordSpace](/engine/6000.5/script-reference/unityengine/shader/keywordspace.md), [Material.enabledKeywords](/engine/6000.5/script-reference/unityengine/material/enabledkeywords.md), [Material.shaderKeywords](/engine/6000.5/script-reference/unityengine/material/shaderkeywords.md).

## IsKeywordEnabled(LocalKeyword)

Checks whether a local shader keyword is enabled for this material.

```csharp
public bool IsKeywordEnabled(in LocalKeyword keyword)
```

### Parameters

**** (\[LocalKeyword]\(/engine/6000.5/script-reference/unityengine/rendering/localkeyword)): The [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md) to check.

### Returns

| Type                                                          | Description                                                                                                                                                 |
| ------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Returns `true` if a [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md) with the given name is enabled for this material. |

### 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).

If you pass in a [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md) and it 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 returns `false`. If you pass a string and a [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md) with that `name` 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 returns `false`.

The version of this function that takes a string as a parameter is slower than the version that takes a [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md). If you call this function more than once, it's best practice to create a [LocalKeyword](/engine/6000.5/script-reference/unityengine/rendering/localkeyword.md) struct, cache it, and use that.

**Note:** A `LocalKeyword` is specific to a single [Shader](/engine/6000.5/script-reference/unityengine/shader.md) or [ComputeShader](/engine/6000.5/script-reference/unityengine/computeshader.md) instance. You cannot use it with other [Shader](/engine/6000.5/script-reference/unityengine/shader.md) or [ComputeShader](/engine/6000.5/script-reference/unityengine/computeshader.md) instances, even if they declare keywords with the same name.

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

// This example iterates over the local shader keywords in the local
// keyword space for a graphics shader. It determines whether each
// keyword is overridden by a global shader keyword and prints its
// state.
public class KeywordExample : MonoBehaviour
{
    public Material material;

    void Start()
    {
        CheckShaderKeywordState();
    }

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

        // Get all the local keywords that affect the Shader
        LocalKeywordSpace keywordSpace = shader.keywordSpace;

        // Iterate over the local keywords
        foreach (LocalKeyword localKeyword in keywordSpace.keywords)
        {
            // If the local keyword is overridable,
            // and a global keyword with the same name exists and is enabled,
            // then Unity uses the global keyword state
            if (localKeyword.isOverridable && Shader.IsKeywordEnabled(localKeyword.name))
            {
                Debug.Log("Local keyword with name of " + localKeyword.name + " is overridden by a global keyword, and is enabled");
            }
            // Otherwise, Unity uses the local keyword state
            else
            {
                string state = material.IsKeywordEnabled(localKeyword) ? "enabled" : "disabled";
                Debug.Log("Local keyword with name of " + localKeyword.name + " is " + 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), [Material.SetKeyword](/engine/6000.5/script-reference/unityengine/material/setkeyword.md), [Shader.keywordSpace](/engine/6000.5/script-reference/unityengine/shader/keywordspace.md), [Material.enabledKeywords](/engine/6000.5/script-reference/unityengine/material/enabledkeywords.md), [Material.shaderKeywords](/engine/6000.5/script-reference/unityengine/material/shaderkeywords.md).
