Version: 2020.1
Experimental: this API is experimental and might be changed or removed in the future.




A static callback that you can implement to set up artifact dependencies to other Assets, and optimize the order your assets are imported.

If you implement this method in a class inheriting from ScriptedImporter, it will be called for all Assets that your class is configured to import, before the importing starts.

Your ScriptedImporter class can then return an array of paths to other Assets that the Asset depends on the import result from (which might depend on how your ScriptedImporter interprets the contents of the file that it is importing).

Unity uses the information you return from this method to import assets in the most efficient order, avoiding the need to re-import assets multiple times where possible.

Note: Each type of importer has a specific priority in the import process. If you specify an asset dependency that belongs to a different import priority, it will not override the import priority, and therefore a repeat import can still occur.

For more information about artifact dependencies check AssetImportContext.DependsOnArtifact. For the dependencies reported using GatherDependenciesFromSourceFile, there is no need to report them again with AssetImportContext.DependsOnArtifact. It however valid to add more artifact dependencies that may be discovered during the actual import.

Method signature:
static string[] GatherDependenciesFromSourceFile(string path)

path - path to asset that can report artifact dependencies before the asset is imported. return value - paths to the assets the asset wants to setup an artifact dependency to.

using UnityEditor.Experimental.AssetImporters;

[ScriptedImporter(1, "my_asset_type", AllowCaching = true)] class MyAssetImporter : ScriptedImporter { static string[] GatherDependenciesFromSourceFile(string assetPath) { // Called before actual import for each changed asset that is imported by this importer type (assets having "my_asset_type" file extension in this example) // Extract the dependencies for the asset specified in assetPath. // For asset dependencies that are discovered, return them in the string array, where the string is the path to asset }

public override void OnImportAsset(AssetImportContext ctx) { // There is no need to call ctx.DependsOnArtfact for the dependencies reported in GatherDependenciesFromSourceFile. } }