Search Unity

  1. We are migrating the Unity Forums to Unity Discussions by the end of July. Read our announcement for more information and let us know if you have any questions.
    Dismiss Notice
  2. Dismiss Notice

Question OnPostProcessBuild bug?

Discussion in 'Testing & Automation' started by vincent-savysoda, Jun 26, 2023.

  1. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    33
    Hi there. I have just discovered something about the OnPostProcessBuild method that I thought worked one way the longest time but have now realized has changed for some time now. So let me explain. For my current multi-platform project, I have a build script for making Steam builds that first removes the "DISABLESTEAMWORKS" symbol(which disables steam from running on non-Steam builds) from the preprocessor definitions list in the OnPreprocessBuild method, then when the build is completed, it readds the definition into the list in the OnPostProcessBuild method. I know for a fact this USED to work. However quite awhile back, weird things started happening, such as certain steam features no longer working properly. Today I realized after some debugging that the OnPostProcessBuild method no longer runs AFTER the build is officially completed, but rather at some point before it, which means that it inserts the DISABLESTEAMWORKS symbol back into the build prior to completion! Below is the code snippet of the functions in question:

    Code (CSharp):
    1. public void OnPreprocessBuild(BuildTarget target, string path)
    2.         {
    3.             // Enable steam bundle if MacOS and isSteamBuild
    4.             SetMacOSLibState(TeamCityBuildScript.isSteamBuild && target == BuildTarget.StandaloneOSX);
    5.        
    6.             // Set asset states to be correct
    7.             if (TeamCityBuildScript.isSteamBuild)
    8.             {
    9.                 SetPurchasingState(false);
    10.                 BuildHelper.DisableUnityPurchasing(target);
    11.                 BuildHelper.EnableSteamSDK(target);
    12.                 PlayerSettings.SetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup, ScriptingImplementation.IL2CPP);
    13.                 //PlayerSettings.SetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup, ScriptingImplementation.Mono2x);
    14.                 SetSplash();
    15.             }
    16.             else
    17.             {
    18.                 SetPurchasingState(true);
    19.                 BuildHelper.EnableUnityPurchasing(target);
    20.                 BuildHelper.DisableSteamSDK(target);
    21.             }
    22.         }
    23.  
    24.         public void OnPostprocessBuild(BuildTarget target, string path)
    25.         {
    26.             if (TeamCityBuildScript.isSteamBuild)
    27.             {
    28.                 SetPurchasingState(true);
    29.                 BuildHelper.DisableSteamSDK(target);
    30.                 PlayerSettings.SetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup, ScriptingImplementation.IL2CPP);
    31.                 //PlayerSettings.SetScriptingBackend(EditorUserBuildSettings.selectedBuildTargetGroup, ScriptingImplementation.IL2CPP);
    32.                 RevertSplash();
    33.                 BuildHelper.GenerateConfiguration(false,false);
    34.             }
    35.         }
    36.  
    37. public static void DisableSteamSDK(BuildTarget target)
    38. {
    39.     var group = BuildPipeline.GetBuildTargetGroup(target);
    40.     string definedSymbols = PlayerSettings.GetScriptingDefineSymbolsForGroup(group);
    41.     definedSymbols = GetSteamDisabledSymbols(target, definedSymbols);
    42.     ApplyNewDefinitionSymbols(group, definedSymbols);
    43. }
    44.  
    45.  

    Now I don't know when exactly this changed or if its intentional. If it is intentional, can you let me know what the correct method is to use in order to achieve the same result? At the moment I'll probably have to implement some workaround to fix this issue, but it would be good to know what the best practice for this is.

    EDIT: I've also just realized that these methods are currently obsolete and should instead use the ones from here instead:
    https://docs.unity3d.com/ScriptReference/Build.IPostprocessBuildWithReport.OnPostprocessBuild.html

    Going to switch over to that to see if it fixes the problem.
     
    Last edited: Jun 26, 2023
  2. vincent-savysoda

    vincent-savysoda

    Joined:
    Dec 19, 2016
    Posts:
    33
    Ok seems like switching over to the new method fixed the issue. Just kinda annoyed the obsolete one was broken without warning. Might want to mention that in documentation if it was intentional.