Quick answer: The class must be public, non-abstract, in an Editor folder (or an Editor-only asmdef). Implement IPostprocessBuildWithReport with the proper signature. Set callbackOrder to control invocation order.

Here is how to fix Unity build postprocess scripts that compile fine but never run after a build. The script must be in an Editor-only assembly and implement the right interface.

The Symptom

You build the player. Console shows build success. Your OnPostprocessBuild method that should copy artifacts or sign the binary never runs.

What Causes This

Wrong asmdef. Class in a runtime assembly does not get scanned for editor callbacks.

Abstract or non-public. Unity scans for concrete public classes implementing the interface.

Wrong interface version. IPostprocessBuild (older) vs IPostprocessBuildWithReport (modern) signatures differ.

The Fix

Step 1: Place in Editor folder. File path includes /Editor/ anywhere, e.g., Assets/Scripts/Editor/MyPostprocessor.cs.

Step 2: Implement the modern interface.

using UnityEditor.Build;
using UnityEditor.Build.Reporting;

public class MyPostprocessor : IPostprocessBuildWithReport
{
    public int callbackOrder => 100;

    public void OnPostprocessBuild(BuildReport report)
    {
        UnityEngine.Debug.Log($"Build complete: {report.summary.outputPath}");
        UnityEngine.Debug.Log($"Total size: {report.summary.totalSize / 1024 / 1024} MB");
    }
}

callbackOrder lower = earlier; multiple postprocessors run in order.

Step 3: For preprocess, mirror the pattern.

public class MyPreprocessor : IPreprocessBuildWithReport
{
    public int callbackOrder => 0;
    public void OnPreprocessBuild(BuildReport report)
    {
        // throw BuildFailedException to abort
    }
}

Step 4: Use BuildPipeline events for delegate-style hooks.

BuildPlayerWindow.RegisterBuildPlayerHandler(args => {
    // custom build flow
});

Useful for completely custom build pipelines.

Step 5: Verify with a Debug.Log. Add a log at the top of OnPostprocessBuild. Build. If you see no log, the class is not being discovered. Check folder/asmdef.

“Editor folder. Public concrete class. IPostprocessBuildWithReport interface. callbackOrder for sequencing.”

Related Issues

For asset pipeline import loop, see AP2 Import Loop. For build size issues, see Build Size Textures.

Editor folder. Right interface. callbackOrder set. Postprocess runs.