# CopyGraphicsStatesForVariant

> Copy all the graphics states from the source variant to the destination variant.

## Definition

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

## CopyGraphicsStatesForVariant(Shader, PassIdentifier, LocalKeyword\[], Shader, PassIdentifier, LocalKeyword\[])

Copy all the graphics states from the source variant to the destination variant.

```csharp
public bool CopyGraphicsStatesForVariant(Shader srcShader, PassIdentifier srcPassId, LocalKeyword[] srcKeywords, Shader dstShader, PassIdentifier dstPassId, LocalKeyword[] dstKeywords)
```

### Parameters

**** (\[Shader]\(/engine/6000.7/script-reference/unityengine/shader)): Shader used in the source variant.**** (\[PassIdentifier]\(/engine/6000.7/script-reference/unityengine/rendering/passidentifier)): PassIdentifier used in the source variant.**** (\[LocalKeyword\[]]\(/engine/6000.7/script-reference/unityengine/rendering/localkeyword)): [LocalKeyword](/engine/6000.7/script-reference/unityengine/rendering/localkeyword.md) array of keywords used in the source variant.**** (\[Shader]\(/engine/6000.7/script-reference/unityengine/shader)): Shader used in the destination variant.**** (\[PassIdentifier]\(/engine/6000.7/script-reference/unityengine/rendering/passidentifier)): PassIdentifier used in the destination variant.**** (\[LocalKeyword\[]]\(/engine/6000.7/script-reference/unityengine/rendering/localkeyword)): [LocalKeyword](/engine/6000.7/script-reference/unityengine/rendering/localkeyword.md) array of keywords used in the destination variant.

### Returns

| Type                                                          | Description                                                          |
| ------------------------------------------------------------- | -------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if at least one new graphics state was copied, false otherwise. |

### Remarks

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

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

public class CopyGraphicsStatesExample : MonoBehaviour
{
    public GraphicsStateCollection graphicsStateCollection;
    public GraphicsStateCollection.ShaderVariant srcVariant;

    void Start()
    {
        if (graphicsStateCollection.ContainsVariant(srcVariant.shader, srcVariant.passId, srcVariant.keywords))
        {
            List<GraphicsStateCollection.ShaderVariant> variants = new List<GraphicsStateCollection.ShaderVariant>();
            graphicsStateCollection.GetVariants(variants);
            foreach (var dstVariant in variants)
            {
                graphicsStateCollection.CopyGraphicsStatesForVariant(srcVariant, dstVariant);
            }
        }
        else
        {
            Debug.Log("srcVariant was not found in graphicsStateCollection! No graphics states were copied.");
        }
    }
}
```

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

## CopyGraphicsStatesForVariant(ShaderVariant, ShaderVariant)

Copy all the graphics states from the source variant to the destination variant.

```csharp
public bool CopyGraphicsStatesForVariant(GraphicsStateCollection.ShaderVariant srcVariant, GraphicsStateCollection.ShaderVariant dstVariant)
```

### Parameters

**** (\[ShaderVariant]\(/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/shadervariant)): Source variant to copy from.**** (\[ShaderVariant]\(/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/shadervariant)): Destination variant to copy to.

### Returns

| Type                                                          | Description                                                          |
| ------------------------------------------------------------- | -------------------------------------------------------------------- |
| [bool](https://learn.microsoft.com/dotnet/api/system.boolean) | True if at least one new graphics state was copied, false otherwise. |

### Remarks

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

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

public class CopyGraphicsStatesExample : MonoBehaviour
{
    public GraphicsStateCollection graphicsStateCollection;
    public GraphicsStateCollection.ShaderVariant srcVariant;

    void Start()
    {
        if (graphicsStateCollection.ContainsVariant(srcVariant.shader, srcVariant.passId, srcVariant.keywords))
        {
            List<GraphicsStateCollection.ShaderVariant> variants = new List<GraphicsStateCollection.ShaderVariant>();
            graphicsStateCollection.GetVariants(variants);
            foreach (var dstVariant in variants)
            {
                graphicsStateCollection.CopyGraphicsStatesForVariant(srcVariant, dstVariant);
            }
        }
        else
        {
            Debug.Log("srcVariant was not found in graphicsStateCollection! No graphics states were copied.");
        }
    }
}
```

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