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!
     
    MilenaRocha and stasofunity like this.
  2. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    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.
     
  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.
     
    stasofunity likes this.
  4. MSplitz-PsychoK

    MSplitz-PsychoK

    Joined:
    May 16, 2015
    Posts:
    1,278
    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.
     
  5. unity_lQ4X4r7U2v_L1Q

    unity_lQ4X4r7U2v_L1Q

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

    jbarraganm

    Joined:
    Feb 15, 2023
    Posts:
    1
    Hi to everyone.
    I am just starting with unity for VR on a 3D model for the office i work for .I tried to buid up a the project and ger similar issues as the other person before. I just don really get what you meant in the comments as I dont really know much about the program and neither know how to code or similiar
    The following are the errors that show up. I hope you can help me out.

    Cheers

    Library\PackageCache\com.unity.visualscripting@1.8.0\Runtime\VisualScripting.Core\Utilities\RuntimeVSUsageUtility.cs(18,13): error CS0103: The name 'SavedVariables' does not exist in the current context

    Library\PackageCache\com.unity.visualscripting@1.8.0\Runtime\VisualScripting.Core\Utilities\RuntimeVSUsageUtility.cs(20,13): error CS0103: The name 'ApplicationVariables' does not exist in the current context

    Error building Player because scripts have compile errors in the editor

    Build completed with a result of 'Failed' in 0 seconds (473 ms)
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

    UnityEditor.BuildPlayerWindow+BuildMethodException: Error building Player because scripts have compile errors in the editor at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002da] in <42a64fd733d9417da1ea3a757ad9a96d>:0
     
  7. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    38,686
    How to troubleshoot build failures:

    First, make a blank project with a single blank scene and prove that it builds successfully.

    If the blank project does NOT build, go fix your Unity installation or your other tools, such as Android SDK, NDK, JDK, etc. It may even be necessary to change to a different version of Unity3D. It is generally best to stay with LTS versions of Unity3D.

    Until you can build a blank project to the target platform, don't fiddle with anything else.

    Once you can build a blank project, now bisect the problem by bringing over parts of your current project and building it one subsystem at a time, perhaps stubbing things out that might trigger compiler errors.

    Most often things that prevent building are third-party libraries such as Firebase.

    Once you identify the subsystem, go to the documentation for it and make sure you are doing it correctly.

    It may also be helpful to work through a tutorial or two for whatever subsystem is making the build fail.

    Android build not building:

    Recently (circa July 2022) there have been reports of Unity's installer failing to install the Android Tools.

    https://forum.unity.com/threads/cant-build-for-android.1306098/

    Here was how I brought up Unity2020.3.41 and the Android SDK 31 on October 30, 2022:

    https://forum.unity.com/threads/aab...y-2021-3-8-with-jdk-1-8.1322211/#post-8551193

    Android Gradle errors and other related stuff:

    https://forum.unity.com/threads/unity-gradle-bug-please-help.1368018/#post-8625789