CollectImportedDependenciesAttribute
Use this method attribute to specify which methods declare dependancies on imported assets. The methods are called by AssetDatabase during import.
Read time 4 minutesLast updated 14 days ago
Definition
- Type: Class
- Namespace: UnityEditor.AssetImporters
- Assembly: UnityEditor.CoreModule
- Inherits from: Attribute
[AttributeUsage(AttributeTargets.Method, Inherited = false, AllowMultiple = true)]public class CollectImportedDependenciesAttribute : Attribute
Remarks
The AssetDatabase imports the dependencies declared in methods with this attribute before importing the dependent assets. This also re-imports the dependent asset whenever the dependency asset changes. Use this declared dependency to safely load dependancies in AssetPostprocessor callbacks.
This example shows how you can declare a dependency between two prefabs imported by the ModelImporter and use them in an AssetPostprocessor.
using UnityEditor;using UnityEditor.AssetImporters;using UnityEngine;public class ProceduralParentPostprocessor : AssetPostprocessor{ private const string s_DependentPath = "Assets/ProceduralPrefab.fbx"; private const string s_DependencyPath = "Assets/DependencyPrefab.fbx"; [CollectImportedDependencies(typeof(ModelImporter), 1)] public static string[] CollectImportedDependenciesForModelImporter(string assetPath) { if (assetPath.Equals(s_DependentPath)) return new[] { s_DependencyPath }; return null; } void OnPostprocessMeshHierarchy(GameObject root) { if (root.name == "ProceduralPrefabRoot") { // Add a new child game object var go = AssetDatabase.LoadMainAssetAtPath(s_DependencyPath) as GameObject; Object.Instantiate(go, root.transform, true); } }}
Note: The attribute supports only native importer types with AssetPostprocessor callbacks: ModelImporter, TextureImporter, AudioImporter, and SpeedTreeImporter.
Constructors
Constructor | Description |
|---|---|
| CollectImportedDependenciesAttribute(System.Type,System.UInt32) | Use the CollectImportedDependencies attribute to declare getters for imported dependencies. |
Properties
Property | Description |
|---|---|
| importerType | The type of the importer for which the imported dependency getter is declared. |
| version | The version of the imported dependency getter. |