Skip to content

Add hooks

Last updated

Implement and register IAmariUnityPackageImportPipelineHook to run your own code at each stage of an import request. Hooks are called for every request, no matter which caller queued it.

Register your hook class with RegisterHook. Hooks must be registered again after every Domain Reload, so registering them in the static constructor of a class marked [InitializeOnLoad] is the most reliable way.

using com.amari_noa.unitypackage_pipeline_core.editor;
using UnityEditor;
[InitializeOnLoad]
internal sealed class ExampleImportHook : IAmariUnityPackageImportPipelineHook
{
static ExampleImportHook()
{
AmariUnityPackageImportPipeline.Service.RegisterHook(new ExampleImportHook());
}
public void OnBeforePackageImport(AmariUnityPackageImportContext context)
{
// Runs before the import
}
public void OnPackageImportCompleted(AmariUnityPackageImportContext context)
{
// Runs after the import completes, before tags are added
}
public void OnImportRequestFinalized(AmariUnityPackageImportResultContext context)
{
// Runs when the request ends
}
}

Registering the same instance twice still calls it only once. Unregister it with UnregisterHook when you no longer need it.

Method When it is called
OnBeforePackageImport Before the import runs
OnPackageImportCompleted After the import completes, before tags are added
OnImportRequestFinalized When the request ends (completed, failed, or cancelled). Called before the ImportRequestFinalized event
  • OnBeforePackageImport and OnPackageImportCompleted are called even when the pre-import change check finds no changes.
  • For a request that fails tag validation, only OnImportRequestFinalized is called.

OnBeforePackageImport and OnPackageImportCompleted receive an AmariUnityPackageImportContext. For what OnImportRequestFinalized receives, see Receive import results.

Property Description
Request / PackagePath The request in progress and the path of its UnityPackage
NormalizedPackagePath The UnityPackage path normalized to an absolute path
Tags The normalized tags
InteractiveMode The value of InteractiveMode when the request started
StartedAtUtc When processing of the request started (UTC)