# DependsOnSourceAsset

> Sets up a dependency on the source file of the asset at a path.

## Definition

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

## DependsOnSourceAsset(string)

Sets up a dependency on the source file of the asset at a path.

```csharp
public void DependsOnSourceAsset(string path)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The project-relative path of the source file that this asset depends on.

### Remarks

A source dependency means that if the other asset's source file changes, Unity reimports this asset too. This is a dependency on the source file itself, not on the import result. To depend on the import result, use [AssetImportContext.DependsOnArtifact](/engine/7000.0/script-reference/unityeditor/assetimporters/assetimportcontext/dependsonartifact.md). The path doesn't have to point to an existing asset. Unity records the location either way, so the importer runs again if an asset is later created at that path, or if the asset there is deleted. This lets an importer produce one result while the file is missing and a different result once it exists. Unity always interprets the string as a project-relative path, so a string in any other form registers a dependency on a location that never resolves. If you already have a GUID, use the overload that takes a GUID. The method throws an exception if `path` is null or empty.

### Examples

```csharp
using UnityEngine;
using UnityEditor;
using UnityEditor.AssetImporters;
using System.IO;

[ScriptedImporter(1, "cube")]
public class CubeWithTextureImporter : ScriptedImporter
{
    public override void OnImportAsset(AssetImportContext ctx)
    {
        var cube = GameObject.CreatePrimitive(PrimitiveType.Cube);

        ctx.AddObjectToAsset("main obj", cube);
        ctx.SetMainObject(cube);

        var material = new Material(Shader.Find("Standard"));

        var lines = File.ReadAllLines(ctx.assetPath);
        var texturePath = lines[0];
        var texture = AssetDatabase.LoadAssetAtPath<Texture>(texturePath);
        if (texture != null)
        {
            material.SetTexture("_MainTex", texture);
            // add a dependency on the texture, such that if it changes or moves, we reimport the asset
            ctx.DependsOnSourceAsset(texturePath);
        }

        ctx.AddObjectToAsset("MaterialWithTexture", material);
    }
}
```

## DependsOnSourceAsset(GUID)

Sets up a dependency on the source file of the asset with the specified GUID.

```csharp
public void DependsOnSourceAsset(GUID guid)
```

### Parameters

**** (GUID): The GUID of the source asset that this asset depends on.

### Remarks

A source dependency means that if the other asset's source file changes, Unity reimports this asset too. This is a dependency on the source file itself, not on the import result. To depend on the import result, use [AssetImportContext.DependsOnArtifact](/engine/7000.0/script-reference/unityeditor/assetimporters/assetimportcontext/dependsonartifact.md). The method throws an exception if `guid` is empty.
