# AddGraphicsStateForVariant

> Adds a new graphics state associated with a shader variant.

## Definition

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

## AddGraphicsStateForVariant(Shader, PassIdentifier, LocalKeyword\[], GraphicsState)

Adds a new graphics state associated with a shader variant.

```csharp
public bool AddGraphicsStateForVariant(Shader shader, PassIdentifier passId, LocalKeyword[] keywords, GraphicsStateCollection.GraphicsState setup)
```

### Parameters

**** (\[Shader]\(/engine/6000.6/script-reference/unityengine/shader)): Shader used in associated variant.**** (\[PassIdentifier]\(/engine/6000.6/script-reference/unityengine/rendering/passidentifier)): PassIdentifier used in associated variant.**** (\[LocalKeyword\[]]\(/engine/6000.6/script-reference/unityengine/rendering/localkeyword)): [LocalKeyword](/engine/6000.6/script-reference/unityengine/rendering/localkeyword.md) array of keywords used in associated variant.**** (\[GraphicsState]\(/engine/6000.6/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate)): GraphicsState to add.

### Returns

| Type                                                          | Description                                                                        |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Returns true if a new graphics state was added to the collection, false otherwise. |

### Remarks

If the specified shader variant does not yet exist in the collection, then it will be added.

**Note**: WebGPU does not fully support manually adding graphics states, results might be unexpected.

Additional Resources: [GraphicsStateCollection.GetGraphicsStatesForVariant](/engine/6000.6/script-reference/unityengine/rendering/graphicsstatecollection/getgraphicsstatesforvariant.md).

### Examples

```csharp
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

public class AddGraphicsStateExample : MonoBehaviour
{
    public GraphicsStateCollection graphicsStateCollection;
    public GraphicsStateCollection.ShaderVariant variant;

    void Start()
    {
        if (graphicsStateCollection.ContainsVariant(variant.shader, variant.passId, variant.keywords))
        {
            List<GraphicsStateCollection.GraphicsState> states = new List<GraphicsStateCollection.GraphicsState>();
            graphicsStateCollection.GetGraphicsStatesForVariant(variant, states);
            foreach (var state in states)
            {
                // Add a new modified version of each existing state for this variant
                GraphicsStateCollection.GraphicsState newState = state;
                newState.wireframe = true;
                graphicsStateCollection.AddGraphicsStateForVariant(variant, newState);
            }
        }
        else
        {
            Debug.Log("variant was not found in graphicsStateCollection! No graphics states were added.");
        }
    }
}
```

## AddGraphicsStateForVariant(ShaderVariant, GraphicsState)

Adds a new graphics state associated with a shader variant.

```csharp
public bool AddGraphicsStateForVariant(GraphicsStateCollection.ShaderVariant variant, GraphicsStateCollection.GraphicsState setup)
```

### Parameters

**** (\[ShaderVariant]\(/engine/6000.6/script-reference/unityengine/rendering/graphicsstatecollection/shadervariant)): Shader variant that the graphics state should be associated with.**** (\[GraphicsState]\(/engine/6000.6/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate)): GraphicsState to add.

### Returns

| Type                                                          | Description                                                                        |
| ------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | Returns true if a new graphics state was added to the collection, false otherwise. |

### Remarks

If the specified shader variant does not yet exist in the collection, then it will be added.

**Note**: WebGPU does not fully support manually adding graphics states, results might be unexpected.

Additional Resources: [GraphicsStateCollection.GetGraphicsStatesForVariant](/engine/6000.6/script-reference/unityengine/rendering/graphicsstatecollection/getgraphicsstatesforvariant.md).

### Examples

```csharp
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Rendering;

public class AddGraphicsStateExample : MonoBehaviour
{
    public GraphicsStateCollection graphicsStateCollection;
    public GraphicsStateCollection.ShaderVariant variant;

    void Start()
    {
        if (graphicsStateCollection.ContainsVariant(variant.shader, variant.passId, variant.keywords))
        {
            List<GraphicsStateCollection.GraphicsState> states = new List<GraphicsStateCollection.GraphicsState>();
            graphicsStateCollection.GetGraphicsStatesForVariant(variant, states);
            foreach (var state in states)
            {
                // Add a new modified version of each existing state for this variant
                GraphicsStateCollection.GraphicsState newState = state;
                newState.wireframe = true;
                graphicsStateCollection.AddGraphicsStateForVariant(variant, newState);
            }
        }
        else
        {
            Debug.Log("variant was not found in graphicsStateCollection! No graphics states were added.");
        }
    }
}
```
