Search Unity

Unity build errors

Discussion in 'Editor & General Support' started by unity_lQ4X4r7U2v_L1Q, Apr 17, 2019.

  1. unity_lQ4X4r7U2v_L1Q

    unity_lQ4X4r7U2v_L1Q

    Joined:
    Feb 11, 2019
    Posts:
    3
    Hi Everyone,

    I am getting the following error when trying to build for PC/Windows:

    UnityEditor.BuildPlayerWindow+BuildMethodException: Error building Player because scripts have compile errors in the editor
    at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x00234] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:190
    at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x0007f] in C:\buildslave\unity\build\Editor\Mono\BuildPlayerWindowBuildMethods.cs:96
    UnityEngine.GUIUtility:processEvent(Int32, IntPtr)


    I have googled this issue, and the answers I found were:

    1. Re-import all assets
    2. Remove the .sln files (Visual Studio solution files) from your project
    3. Change the build folder to outside the project
    4. Remove the Plugins folder from the Assets folder

    I did 1-3 and the problem remains. #4 doesn't make since, because I have plugins which are required in that folder.
    The project is compiling and running inside Unity, but it just won't build.

    My Unity version is 2018.3.4f1, if that helps...

    Can you please advice? This is extremely frustrating and I am fighting this over 2 days now


    Thanks!
     
  2. Gambit-MSplitz

    Gambit-MSplitz

    Joined:
    May 16, 2015
    Posts:
    1,157
    Run a search through your entire codebase for "UnityEditor". Any script that references "UnityEditor" must either be inside a folder called "Editor", or must have all references of "UnityEditor" wrapped in pre-compile flags to exclude them from a build. By pre-compile flag, I mean something like "#if UNITY_EDITOR" / "#endif".


    The reason this is suggested is because some plugins may have editor-only code.
     
    unity_lQ4X4r7U2v_L1Q likes this.
  3. unity_lQ4X4r7U2v_L1Q

    unity_lQ4X4r7U2v_L1Q

    Joined:
    Feb 11, 2019
    Posts:
    3
    Hi Gambit,

    Thank you for your response!

    I found that the SteamVR asset I am using has many references to UnityEditor, but I don't think modifying them is a good idea.
    However, I did found one reference in my code, and removed it (temporarily), and surprisingly it solved the problem. How come SteamVR can use UnityEditor in their code and it doesn't cause build errors?

    Thanks.
     
  4. Gambit-MSplitz

    Gambit-MSplitz

    Joined:
    May 16, 2015
    Posts:
    1,157
    Any script inside of an "Editor" folder does not get included in a build. Any code between a "#if UNITY_EDITOR" and "#endif" also does not get included in a build. Code that is not included in a build cannot cause errors during a build or outside of the editor.

    The meta files of some plugins may exclude the associated plugin from certain types of builds via platform settings.
     
    unity_lQ4X4r7U2v_L1Q likes this.
  5. unity_lQ4X4r7U2v_L1Q

    unity_lQ4X4r7U2v_L1Q

    Joined:
    Feb 11, 2019
    Posts:
    3
    Thanks for the help. It solved my problem!