# AddGraphicsStatesFromReference

> Generates and adds new graphics states from arrays of assets, using a reference graphics state to initialize unspecified values.

## Definition

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

## AddGraphicsStatesFromReference(GraphicsState, Mesh\[], Material\[], int, NativeArray\<AttachmentDescriptor>, NativeArray\<SubPassDescriptor>, int, int, int)

Generates and adds new graphics states from arrays of assets, using a reference graphics state to initialize unspecified values.

```csharp
public bool AddGraphicsStatesFromReference(GraphicsStateCollection.GraphicsState refState, Mesh[] meshes, Material[] materials, int samples, NativeArray<AttachmentDescriptor> attachments, NativeArray<SubPassDescriptor> subPasses, int subPassIndex = 0, int depthAttachmentIndex = -1, int shadingRateIndex = -1)
```

### Parameters

**** (\[GraphicsState]\(/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate)): The reference [GraphicsStateCollection.GraphicsState](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate.md) to use as a template for initializing unspecified values.**** (\[Mesh\[]]\(/engine/6000.7/script-reference/unityengine/mesh)): An array of meshes to generate graphics states from. This array must be the same length as the `materials` array.**** (\[Material\[]]\(/engine/6000.7/script-reference/unityengine/material)): An array of materials specifying the shader variant(s) for each generated graphics state. This array must be the same length as the `meshes` array.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of samples per pixel in this rendering configuration.**** (\[NativeArray\<AttachmentDescriptor>]\(/engine/6000.7/script-reference/unity/collections/nativearray1)): The array of color attachments used in this rendering configuration.**** (\[NativeArray\<SubPassDescriptor>]\(/engine/6000.7/script-reference/unity/collections/nativearray1)): The array containing information of each subpass.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the active subpass in this rendering configuration.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the attachment to be used as the depth/stencil buffer for this rendering configuration.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the attachment to be used as the shading rate image for this rendering configuration.

### Returns

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

### Remarks

This function operates like [GraphicsStateCollection.AddGraphicsStates](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstates.md), but instead of using default values for [GraphicsStateCollection.GraphicsState](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate.md) fields, it copies values from the provided `refState` for any fields not determined by the input parameters.

Additional Resources: [GraphicsStateCollection.AddGraphicsStates](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstates.md), [GraphicsStateCollection.AddGraphicsStateForVariant](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstateforvariant.md), [CommandBuffer.BeginRenderPass](/engine/6000.7/script-reference/unityengine/rendering/commandbuffer/beginrenderpass.md).

## AddGraphicsStatesFromReference(GraphicsState, Mesh\[], Material\[], GlobalKeyword\[], int, NativeArray\<AttachmentDescriptor>, NativeArray\<SubPassDescriptor>, int, int, int)

Generates and adds new graphics states from arrays of assets, using a reference graphics state to initialize unspecified values.

```csharp
public bool AddGraphicsStatesFromReference(GraphicsStateCollection.GraphicsState refState, Mesh[] meshes, Material[] materials, GlobalKeyword[] globalKeywords, int samples, NativeArray<AttachmentDescriptor> attachments, NativeArray<SubPassDescriptor> subPasses, int subPassIndex = 0, int depthAttachmentIndex = -1, int shadingRateIndex = -1)
```

### Parameters

**** (\[GraphicsState]\(/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate)): The reference [GraphicsStateCollection.GraphicsState](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate.md) to use as a template for initializing unspecified values.**** (\[Mesh\[]]\(/engine/6000.7/script-reference/unityengine/mesh)): An array of meshes to generate graphics states from. This array must be the same length as the `materials` array.**** (\[Material\[]]\(/engine/6000.7/script-reference/unityengine/material)): An array of materials specifying the shader variant(s) for each generated graphics state. This array must be the same length as the `meshes` array.**** (\[GlobalKeyword\[]]\(/engine/6000.7/script-reference/unityengine/rendering/globalkeyword)): An array of [GlobalKeyword](/engine/6000.7/script-reference/unityengine/rendering/globalkeyword.md) objects to use in conjunction with each material's enabled keywords when generating shader variants.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The number of samples per pixel in this rendering configuration.**** (\[NativeArray\<AttachmentDescriptor>]\(/engine/6000.7/script-reference/unity/collections/nativearray1)): The array of color attachments used in this rendering configuration.**** (\[NativeArray\<SubPassDescriptor>]\(/engine/6000.7/script-reference/unity/collections/nativearray1)): The array containing information of each subpass.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the active subpass in this rendering configuration.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the attachment to be used as the depth/stencil buffer for this rendering configuration.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the attachment to be used as the shading rate image for this rendering configuration.

### Returns

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

### Remarks

This function operates like [GraphicsStateCollection.AddGraphicsStates](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstates.md), but instead of using default values for [GraphicsStateCollection.GraphicsState](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate.md) fields, it copies values from the provided `refState` for any fields not determined by the input parameters.

Additional Resources: [GraphicsStateCollection.AddGraphicsStates](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstates.md), [GraphicsStateCollection.AddGraphicsStateForVariant](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstateforvariant.md), [CommandBuffer.BeginRenderPass](/engine/6000.7/script-reference/unityengine/rendering/commandbuffer/beginrenderpass.md).

## AddGraphicsStatesFromReference(GraphicsState, Mesh\[], Material\[])

Generates and adds new graphics states from arrays of assets, using a reference graphics state to initialize unspecified values.

```csharp
public bool AddGraphicsStatesFromReference(GraphicsStateCollection.GraphicsState refState, Mesh[] meshes, Material[] materials)
```

### Parameters

**** (\[GraphicsState]\(/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate)): The reference [GraphicsStateCollection.GraphicsState](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate.md) to use as a template for initializing unspecified values.**** (\[Mesh\[]]\(/engine/6000.7/script-reference/unityengine/mesh)): An array of meshes to generate graphics states from. This array must be the same length as the `materials` array.**** (\[Material\[]]\(/engine/6000.7/script-reference/unityengine/material)): An array of materials specifying the shader variant(s) for each generated graphics state. This array must be the same length as the `meshes` array.

### Returns

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

### Remarks

This function operates like [GraphicsStateCollection.AddGraphicsStates](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstates.md), but instead of using default values for [GraphicsStateCollection.GraphicsState](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate.md) fields, it copies values from the provided `refState` for any fields not determined by the input parameters.

Additional Resources: [GraphicsStateCollection.AddGraphicsStates](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstates.md), [GraphicsStateCollection.AddGraphicsStateForVariant](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstateforvariant.md), [CommandBuffer.BeginRenderPass](/engine/6000.7/script-reference/unityengine/rendering/commandbuffer/beginrenderpass.md).

## AddGraphicsStatesFromReference(GraphicsState, Mesh\[], Material\[], GlobalKeyword\[])

Generates and adds new graphics states from arrays of assets, using a reference graphics state to initialize unspecified values.

```csharp
public bool AddGraphicsStatesFromReference(GraphicsStateCollection.GraphicsState refState, Mesh[] meshes, Material[] materials, GlobalKeyword[] globalKeywords)
```

### Parameters

**** (\[GraphicsState]\(/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate)): The reference [GraphicsStateCollection.GraphicsState](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate.md) to use as a template for initializing unspecified values.**** (\[Mesh\[]]\(/engine/6000.7/script-reference/unityengine/mesh)): An array of meshes to generate graphics states from. This array must be the same length as the `materials` array.**** (\[Material\[]]\(/engine/6000.7/script-reference/unityengine/material)): An array of materials specifying the shader variant(s) for each generated graphics state. This array must be the same length as the `meshes` array.**** (\[GlobalKeyword\[]]\(/engine/6000.7/script-reference/unityengine/rendering/globalkeyword)): An array of [GlobalKeyword](/engine/6000.7/script-reference/unityengine/rendering/globalkeyword.md) objects to use in conjunction with each material's enabled keywords when generating shader variants.

### Returns

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

### Remarks

This function operates like [GraphicsStateCollection.AddGraphicsStates](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstates.md), but instead of using default values for [GraphicsStateCollection.GraphicsState](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/graphicsstate.md) fields, it copies values from the provided `refState` for any fields not determined by the input parameters.

Additional Resources: [GraphicsStateCollection.AddGraphicsStates](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstates.md), [GraphicsStateCollection.AddGraphicsStateForVariant](/engine/6000.7/script-reference/unityengine/rendering/graphicsstatecollection/addgraphicsstateforvariant.md), [CommandBuffer.BeginRenderPass](/engine/6000.7/script-reference/unityengine/rendering/commandbuffer/beginrenderpass.md).
