Search code examples
c#unity-game-enginegame-development

Unity: IPreprocessBuildWithReport is not running on Build


I am a new with Unity and I have been trying to build a Unity project where when it is built, it can also copy some files with the game.exe in the Build folder. For that, I need to understand how IPreprocessBuildWithReport works.

I have created a C# script called MyCustomBuildProcessor.cs and put it inside: Assets\Scripts\Editor The script is as follows:

//Implement this function to receive a callback before the build is started.
using UnityEditor;
using UnityEditor.Build;
using UnityEditor.Build.Reporting;
using UnityEngine;

class MyCustomBuildProcessor : IPreprocessBuildWithReport
{
    public int callbackOrder { get { return 0; } }
    public void OnPreprocessBuild(BuildReport report)
    {
        Debug.Log("MyCustomBuildProcessor.OnPreprocessBuild for target " + report.summary.platform + " at path " + report.summary.outputPath);
    }
}

To my understanding, this script should run when I build the project, but the Log is not shown in the console. Can someone explain to me what I am doing wrong?

My build setting is as follows: Unity Build Settings Image , Unity Project Files

My Unity version is: 2022.1.20f1

I have tried building in different version like 2021.3.10f1 and tried placing the file in outside the Editor folder but nothing has worked. Maybe there is something basic that I am missing. I am new to the Unity scene so I have no idea what I am doing wrong.


Solution

  • You need to just uncheck the "Clear on Recompile" toggle:

    Clear on Recompile