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
\$\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\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.