# DependsOnArtifact

> Setup artifact dependency to an asset.

## Definition

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

## DependsOnArtifact(ArtifactKey)

Setup artifact dependency to an asset.

```csharp
public void DependsOnArtifact(ArtifactKey key)
```

### Parameters

**** (\[ArtifactKey]\(/engine/6000.0/script-reference/unityeditor/experimental/artifactkey)): The artifact key of the artifact dependency.

### Remarks

An artifact dependency is a dependency where an Asset depends on the import result (known as an artifact) of another Asset. If you change an Asset that has been marked as a dependency, all Assets which depend on it will also get reimported (after the dependency has been imported).

Note: If you specify an Asset as a dependency that doesn't exist or hasn't yet been imported, the dependency is still registered. It is registered as an un-imported Asset. When the Asset is later imported, all Assets which depend on it will also get reimported.

### Examples

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

class TextureInfo : ScriptableObject
{
    public int height;
}

[ScriptedImporter(1, "cube")]
public class CubeWithTextureImporter : ScriptedImporter
{
    public override void OnImportAsset(AssetImportContext ctx)
    {
        var assetDependency = "Assets/MyTexture.png";

        ctx.DependsOnArtifact(assetDependency);

        var texture = AssetDatabase.LoadAssetAtPath<Texture>(assetDependency);

        if (texture != null)
        {
            var textureInfo = ScriptableObject.CreateInstance<TextureInfo>();
            textureInfo.height = texture.height;
            ctx.AddObjectToAsset("TextureInfo", textureInfo);
        }
    }
}
```

## DependsOnArtifact(GUID)

Setup artifact dependency to an asset.

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

### Parameters

**** (GUID): The guid of the artifact dependency.

### Remarks

An artifact dependency is a dependency where an Asset depends on the import result (known as an artifact) of another Asset. If you change an Asset that has been marked as a dependency, all Assets which depend on it will also get reimported (after the dependency has been imported).

Note: If you specify an Asset as a dependency that doesn't exist or hasn't yet been imported, the dependency is still registered. It is registered as an un-imported Asset. When the Asset is later imported, all Assets which depend on it will also get reimported.

### Examples

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

class TextureInfo : ScriptableObject
{
    public int height;
}

[ScriptedImporter(1, "cube")]
public class CubeWithTextureImporter : ScriptedImporter
{
    public override void OnImportAsset(AssetImportContext ctx)
    {
        var assetDependency = "Assets/MyTexture.png";

        ctx.DependsOnArtifact(assetDependency);

        var texture = AssetDatabase.LoadAssetAtPath<Texture>(assetDependency);

        if (texture != null)
        {
            var textureInfo = ScriptableObject.CreateInstance<TextureInfo>();
            textureInfo.height = texture.height;
            ctx.AddObjectToAsset("TextureInfo", textureInfo);
        }
    }
}
```

## DependsOnArtifact(string)

Setup artifact dependency to an asset.

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

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The path of the Asset whose artifact should be the dependency. Note: Although the dependency is the artifact (import result) which is stored in the library folder, this parameter is the path to the Asset in the Assets folder, and *not* a path to the artifact in the Library folder.

### Remarks

An artifact dependency is a dependency where an Asset depends on the import result (known as an artifact) of another Asset. If you change an Asset that has been marked as a dependency, all Assets which depend on it will also get reimported (after the dependency has been imported).

Note: If you specify an Asset as a dependency that doesn't exist or hasn't yet been imported, the dependency is still registered. It is registered as an un-imported Asset. When the Asset is later imported, all Assets which depend on it will also get reimported.

### Examples

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

class TextureInfo : ScriptableObject
{
    public int height;
}

[ScriptedImporter(1, "cube")]
public class CubeWithTextureImporter : ScriptedImporter
{
    public override void OnImportAsset(AssetImportContext ctx)
    {
        var assetDependency = "Assets/MyTexture.png";

        ctx.DependsOnArtifact(assetDependency);

        var texture = AssetDatabase.LoadAssetAtPath<Texture>(assetDependency);

        if (texture != null)
        {
            var textureInfo = ScriptableObject.CreateInstance<TextureInfo>();
            textureInfo.height = texture.height;
            ctx.AddObjectToAsset("TextureInfo", textureInfo);
        }
    }
}
```
