# UpdateShaderAsset

> Replaces the existing source code in the specified shader with the source code in the supplied string.

## Definition

* **Type:** Method
* **Namespace:** [UnityEditor](/engine/6000.0/script-reference/unityeditor.md)
* **Assembly:** UnityEditor

## UpdateShaderAsset(AssetImportContext, Shader, string, bool)

Replaces the existing source code in the specified shader with the source code in the supplied string.

```csharp
public static void UpdateShaderAsset(AssetImportContext context, Shader shader, string source, bool compileInitialShaderVariants)
```

### Parameters

**** (\[AssetImportContext]\(/engine/6000.0/script-reference/unityeditor/assetimporters/assetimportcontext)): A context object that the asset system needs to register shader dependencies properly.**** (\[Shader]\(/engine/6000.0/script-reference/unityengine/shader)): The [Shader](/engine/6000.0/script-reference/unityengine/shader.md) to update.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): A string that contains a shader written in [ShaderLab](/engine/6000.0/manual/materials-and-shaders/shaders/reference/sl-reference/sl-shader-object/sl-shader.md) code.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Set to true to compile the [ShaderLab](/engine/6000.0/manual/materials-and-shaders/shaders/reference/sl-reference/sl-shader-object/sl-shader.md) code contained in the source string; otherwise false.

## UpdateShaderAsset(Shader, string)

Replaces the existing source code in the specified shader with the source code in the supplied string.

```csharp
public static void UpdateShaderAsset(Shader shader, string source)
```

### Parameters

**** (\[Shader]\(/engine/6000.0/script-reference/unityengine/shader)): The [Shader](/engine/6000.0/script-reference/unityengine/shader.md) to update.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): A string that contains a shader written in [ShaderLab](/engine/6000.0/manual/materials-and-shaders/shaders/reference/sl-reference/sl-shader-object/sl-shader.md) code.

## UpdateShaderAsset(Shader, string, bool)

Replaces the existing source code in the specified shader with the source code in the supplied string.

```csharp
public static void UpdateShaderAsset(Shader shader, string source, bool compileInitialShaderVariants)
```

### Parameters

**** (\[Shader]\(/engine/6000.0/script-reference/unityengine/shader)): The [Shader](/engine/6000.0/script-reference/unityengine/shader.md) to update.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): A string that contains a shader written in [ShaderLab](/engine/6000.0/manual/materials-and-shaders/shaders/reference/sl-reference/sl-shader-object/sl-shader.md) code.**** (\[bool]\(https\://learn.microsoft.com/dotnet/api/system.boolean)): Set to true to compile the [ShaderLab](/engine/6000.0/manual/materials-and-shaders/shaders/reference/sl-reference/sl-shader-object/sl-shader.md) code contained in the source string; otherwise false.
