# CreateShaderAsset

> Creates a new Shader object from the provided source code string. You can use this method alongside the ScriptedImporter to create custom shader generation tools in the Editor.

## Definition

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

## CreateShaderAsset(AssetImportContext, string, bool)

Creates a new [Shader](/engine/6000.7/script-reference/unityengine/shader.md) object from the provided source code string. You can use this method alongside the [ScriptedImporter](/engine/6000.7/script-reference/unityeditor/assetimporters/scriptedimporter.md) to create custom shader generation tools in the Editor.

```csharp
public static Shader CreateShaderAsset(AssetImportContext context, string source, bool compileInitialShaderVariants)
```

### Parameters

**** (\[AssetImportContext]\(/engine/6000.7/script-reference/unityeditor/assetimporters/assetimportcontext)): A context object that the asset system needs to register shader dependencies properly.**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): A string that contains a shader written in [ShaderLab](/engine/6000.7/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.7/manual/materials-and-shaders/shaders/reference/sl-reference/sl-shader-object/sl-shader.md) code contained in the source string; otherwise false.

### Returns

| Type                                                            | Description |
| --------------------------------------------------------------- | ----------- |
| [Shader](/engine/6000.7/script-reference/unityengine/shader.md) |             |

## CreateShaderAsset(string)

Creates a new [Shader](/engine/6000.7/script-reference/unityengine/shader.md) object from the provided source code string. You can use this method alongside the [ScriptedImporter](/engine/6000.7/script-reference/unityeditor/assetimporters/scriptedimporter.md) to create custom shader generation tools in the Editor.

```csharp
public static Shader CreateShaderAsset(string source)
```

### Parameters

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

### Returns

| Type                                                            | Description |
| --------------------------------------------------------------- | ----------- |
| [Shader](/engine/6000.7/script-reference/unityengine/shader.md) |             |

## CreateShaderAsset(string, bool)

Creates a new [Shader](/engine/6000.7/script-reference/unityengine/shader.md) object from the provided source code string. You can use this method alongside the [ScriptedImporter](/engine/6000.7/script-reference/unityeditor/assetimporters/scriptedimporter.md) to create custom shader generation tools in the Editor.

```csharp
public static Shader CreateShaderAsset(string source, bool compileInitialShaderVariants)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): A string that contains a shader written in [ShaderLab](/engine/6000.7/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.7/manual/materials-and-shaders/shaders/reference/sl-reference/sl-shader-object/sl-shader.md) code contained in the source string; otherwise false.

### Returns

| Type                                                            | Description |
| --------------------------------------------------------------- | ----------- |
| [Shader](/engine/6000.7/script-reference/unityengine/shader.md) |             |
