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.
- Set the order value explicitly.
- Put the callback that writes a value at a lower order.
- Put the callback that reads it at a higher order.
- 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 includedExpected 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.
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.