1
\$\begingroup\$

I would like to listen for an event that some asset (prefab, precisely) has been modified. To my surprise, there's no such event in AssetModificationProcessor.

Is there any way to do this in Unity?

\$\endgroup\$

1 Answer 1

1
\$\begingroup\$

You can make use of the AssetPostProcessor to post-process your assets in Unity Editor.

Here is an extract of the code I used in a project before.

using UnityEditor;
using UnityEngine;
using System.Collections;

public class MyPostProcessor : AssetPostprocessor {
    public delegate void PostProcessAsset();
    public static event PostProcessAsset PostProcessAssetHandler;

    public static void OnPostprocessAllAssets(
        string[] importedAssets, string[] deletedAssets, string[] movedAssets, string[] movedFromAssetPaths) {
        if (PostProcessAssetHandler != null) {
            PostProcessAssetHandler();
        }
    }
}

Register any functions you want to execute to the event PostProcessAsset.

\$\endgroup\$
1
  • \$\begingroup\$ In case anyone is wondering, that will only work if you want to listen to the event from a custom editor script in an Editor folder. If you want a standard monobehavior class to respond to a post-process event, you must find another solution. \$\endgroup\$
    – Ph0t0n
    Oct 6, 2022 at 7:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .