Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question IPreprocessBuildWithReport.OnPreprocessBuild not running

Discussion in 'Editor & General Support' started by kurifodo, Feb 18, 2023.

  1. kurifodo

    kurifodo

    Joined:
    Jan 17, 2019
    Posts:
    33
    Unity Version: 2021.3.18f1

    I'm following the Unity docs to run a script pre-build:
    https://docs.unity3d.com/ScriptReference/Build.IPreprocessBuildWithReport.OnPreprocessBuild.html

    I've created the following script and dropped it into an editor folder: <project>/Assets/Editor

    I expected the log statement to print to the console when running via the Play Button, but it did not. I have verified my logs are viewable (other logs are coming in). I also checked the editor.log file (%LOCALAPPDATA%\Unity\Editor\Editor.log) and it contained no mention of my script.

    Is my expectation that this script should be executed with the Play Button wrong?

    Code (CSharp):
    1. using UnityEditor.Build;
    2. using UnityEditor.Build.Reporting;
    3.  
    4. public class BuildVersionProcessor : IPreprocessBuildWithReport
    5. {
    6.     public int callbackOrder => 0;
    7.  
    8.     public void OnPreprocessBuild( BuildReport report )
    9.     {
    10.         UnityEngine.Debug.Log( "I'm here..." );
    11.     }
    12. }
     
    Last edited: Feb 18, 2023
  2. bmccowan

    bmccowan

    Joined:
    Jan 12, 2016
    Posts:
    4
    I'm using 2021.3.16f, and IPreprocessBuildWithReport.OnPreprocessBuild doesn't seem to log anything to the console. However, the function still executes, and it does log to the console but the output is cleared before we can see anything. So, if there's an error in your code, you'll have to look at the logs to see what the error is (https://docs.unity3d.com/Manual/LogFiles.html).
     
  3. kurifodo

    kurifodo

    Joined:
    Jan 17, 2019
    Posts:
    33
    I mentioned I did look at my editor logs in my post. It does not contain my log statement. Post your code and repro steps please.
     
  4. bmccowan

    bmccowan

    Joined:
    Jan 12, 2016
    Posts:
    4
    I attached my test code. Drop it in the Editor folder, then build.
    On Windows, open the command line and paste:

    notepad %LOCALAPPDATA%\Unity\Editor\Editor.log
    Then hit Ctrl + f and type: Test Build Preprocessor
    It should find the log

    I also just saw that you're hitting the Play button to test. IPreprocessBuildWithReport will only work when you make a build.
     

    Attached Files:

    kurifodo likes this.
  5. danielszweda_math

    danielszweda_math

    Joined:
    Jun 20, 2023
    Posts:
    2
    Hey there! If anyone happens to stumble upon this post in the future. No need to go through the logs, just disable the "Clear on build" option in the console by clicking on the little arrow on the "Clear" button. Hope this makes things easier for you!
     
    ksf000, Rachan and Ladder14 like this.
  6. Rachan

    Rachan

    Joined:
    Dec 3, 2012
    Posts:
    758
    Thank you very much!

    But I have to disable all Clear options