# AddVariants

> Adds one or more new shader variants to the collection.

## Definition

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

## AddVariants(Material, int)

Adds one or more new shader variants to the collection.

```csharp
public bool AddVariants(Material mat, int subshaderIndex = -1)
```

### Parameters

**** (\[Material]\(/engine/6000.5/script-reference/unityengine/material)): **** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the subshader within the shader used in the variant.

### Returns

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

### Remarks

If `subshaderIndex` is not specified, then one [ShaderVariantCollection.ShaderVariant](/engine/6000.5/script-reference/unityengine/shadervariantcollection/shadervariant.md) will attempt to be added for each shader pass in every SubShader of the `material` parameter's [Shader](/engine/6000.5/script-reference/unityengine/shader.md). Otherwise, at most [Shader.GetPassCountInSubshader](/engine/6000.5/script-reference/unityengine/shader/getpasscountinsubshader.md) number of variants will be added using the specified `subshaderIndex`.

All generated shader variants will use the set of [Material.enabledKeywords](/engine/6000.5/script-reference/unityengine/material/enabledkeywords.md) combined with the global shader keywords that are **currently enabled** in the active context, unless explicitly provided via `globalKeywords`.

Additional Resources: [GraphicsStateCollection.AddVariant](/engine/6000.5/script-reference/unityengine/rendering/graphicsstatecollection/addvariant.md), [GraphicsStateCollection.RemoveVariant](/engine/6000.5/script-reference/unityengine/rendering/graphicsstatecollection/removevariant.md), [GraphicsStateCollection.ContainsVariant](/engine/6000.5/script-reference/unityengine/rendering/graphicsstatecollection/containsvariant.md).

## AddVariants(Material, GlobalKeyword\[], int)

Adds one or more new shader variants to the collection.

```csharp
public bool AddVariants(Material mat, GlobalKeyword[] globalKeywords, int subshaderIndex = -1)
```

### Parameters

**** (\[Material]\(/engine/6000.5/script-reference/unityengine/material)): **** (\[GlobalKeyword\[]]\(/engine/6000.5/script-reference/unityengine/rendering/globalkeyword)): [GlobalKeyword](/engine/6000.5/script-reference/unityengine/rendering/globalkeyword.md) array of global keywords to use with the material's enabled keywords in the variants.**** (\[int]\(https\://learn.microsoft.com/dotnet/api/system.int32)): The index of the subshader within the shader used in the variant.

### Returns

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

### Remarks

If `subshaderIndex` is not specified, then one [ShaderVariantCollection.ShaderVariant](/engine/6000.5/script-reference/unityengine/shadervariantcollection/shadervariant.md) will attempt to be added for each shader pass in every SubShader of the `material` parameter's [Shader](/engine/6000.5/script-reference/unityengine/shader.md). Otherwise, at most [Shader.GetPassCountInSubshader](/engine/6000.5/script-reference/unityengine/shader/getpasscountinsubshader.md) number of variants will be added using the specified `subshaderIndex`.

All generated shader variants will use the set of [Material.enabledKeywords](/engine/6000.5/script-reference/unityengine/material/enabledkeywords.md) combined with the global shader keywords that are **currently enabled** in the active context, unless explicitly provided via `globalKeywords`.

Additional Resources: [GraphicsStateCollection.AddVariant](/engine/6000.5/script-reference/unityengine/rendering/graphicsstatecollection/addvariant.md), [GraphicsStateCollection.RemoveVariant](/engine/6000.5/script-reference/unityengine/rendering/graphicsstatecollection/removevariant.md), [GraphicsStateCollection.ContainsVariant](/engine/6000.5/script-reference/unityengine/rendering/graphicsstatecollection/containsvariant.md).
