| Parameter | Description |
|---|---|
| path | The project-relative path of the asset whose import result this asset depends on. This is the path to the source asset in the Assets folder, not to the artifact in the Library folder. |
Sets up a dependency on the import result of the asset at a path.
An artifact dependency means that this asset depends on the import result, known as an artifact, of another asset. If the other asset changes, Unity reimports it and then reimports every asset that depends on it. If the other asset doesn't exist or isn't imported yet, Unity registers the dependency anyway, and reimports this asset when the other asset is imported. Where possible, use the overload that takes a GUID, because the GUID stays the same when you move or rename the asset. The method throws an exception if path is null or empty.
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); } } }
| Parameter | Description |
|---|---|
| guid | The GUID of the asset whose import result this asset depends on. |
Sets up a dependency on the import result of the asset with the specified GUID.
An artifact dependency means that this asset depends on the import result, known as an artifact, of another asset. If the other asset changes, Unity reimports it and then reimports every asset that depends on it. If the other asset doesn't exist or isn't imported yet, Unity registers the dependency anyway, and reimports this asset when the other asset is imported. The GUID stays the same when you move or rename the asset, so this overload is more reliable than the one that takes a path. The method throws an exception if guid is empty.
| Parameter | Description |
|---|---|
| key | The artifact key that identifies the import result this asset depends on. |
Sets up a dependency on the import result that the specified artifact key identifies.
An artifact dependency means that this asset depends on the import result, known as an artifact, of another asset. If the other asset changes, Unity reimports it and then reimports every asset that depends on it. If the other asset doesn't exist or isn't imported yet, Unity registers the dependency anyway, and reimports this asset when the other asset is imported. The method throws an exception if key isn't valid.
| Parameter | Description |
|---|---|
| artifact | A reference to the asset whose import result this asset depends on. |
ArtifactDependencyResult An ArtifactDependencyResult value that shows whether the method registered the dependency, or why it didn't.
Sets up a dependency on the import result of the asset that an object reference points to.
Unlike the overloads that take a path or a GUID, this method doesn't throw. It sets up the dependency when it can, and reports the result. Using an Object reference loads the referenced asset as soon as Unity deserializes the importer. To avoid that, use the overload that takes a LazyLoadReference<T0>.
| Parameter | Description |
|---|---|
| artifact | A lazy-load reference to the asset whose import result this asset depends on. |
ArtifactDependencyResult An ArtifactDependencyResult value that shows whether the method registered the dependency, or why it didn't.
Sets up a dependency on the import result of the asset that a lazy-load reference points to.
Unlike the overloads that take a path or a GUID, this method doesn't throw. It sets up the dependency when it can, and reports the result. This overload is preferred, because a LazyLoadReference<T0> doesn't load the referenced asset when Unity deserializes the importer.
using UnityEditor; using UnityEditor.AssetImporters; using UnityEngine;
[ScriptedImporter(1, "myimporter")] public class MyImporter : ScriptedImporter { public LazyLoadReference<AnimationClip> sourceClip; public LazyLoadReference<GameObject> sourcePrefab; public Texture2D sourceTexture;
public override void OnImportAsset(AssetImportContext ctx) { // Set up dependencies up front, before any conditional early-return, so they are always registered. ctx.DependsOnArtifact(sourceClip); ctx.DependsOnArtifact(sourcePrefab); ctx.DependsOnArtifact(sourceTexture);
if (sourceClip.asset != null && sourcePrefab.asset != null && sourceTexture != null) { // Do import stuff.. } } }