Diagram · Build callbacks and what each stage can still change
Diagram · Build callbacks and what each stage can still change View full-size figure

Each callback can do different things

A pre-build callback can still change settings and assets. A scene processing callback intervenes per scene. A post-build callback can inspect the output but arrives too late to change what exists. Where you place a check decides whether it is a gate or a report.

To make it a gate, throw

Logging lets the build continue. Conditions that must stop the build have to raise an exception.

class StampAndGate : IPreprocessBuildWithReport
{
    public int callbackOrder => 0;

    public void OnPreprocessBuild(BuildReport report)
    {
        if (EditorUserBuildSettings.development)
            throw new BuildFailedException("release build must not be a development build");

        PlayerSettings.bundleVersion = ReadVersionFromFile();
    }
}

Without an order they overwrite each other

With several callbacks, execution order decides the result. If one stamps a version and another reads it to validate, a reversed order makes the check read the old value.

  1. Set the order value explicitly.
  2. Put the callback that writes a value at a lower order.
  3. Put the callback that reads it at a higher order.
  4. Log which callback did what.

Use post-build for the record

Output size, included scene count, stripping results: post-build is the right place to record those. It writes rather than blocks.

[Pre]  version stamped 1.0.2
[Pre]  gate passed: not a development build
[Post] output size recorded, 4 scenes included

Expected result and next step

When a condition that must be blocked really stops the build before compilation, this stage is done. Whether that gate still works is the next question, and testing it with deliberately broken input was covered in an earlier post.

Verification scope

Official documentation review

Verified

Reviewed the article's code and procedure against official Unity documentation and marked it ready for publication. This is not a claim of an independent Unity project or device reproduction; version- or device-specific reports will be checked in that environment as follow-up.

Official documentation checkedScriptable Build Pipeline documentation ↗