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

HELP I HAVE 3 ERRORS WHEN BUILDING PROJECT

Discussion in 'Scripting' started by ScottGameDevelopment, Jul 25, 2020.

  1. ScottGameDevelopment

    ScottGameDevelopment

    Joined:
    Apr 7, 2020
    Posts:
    42
    Hello Community i have 4 errors and when i go to check them there not there and the stupid error log is lying

    I did find one that does like EditorApplication and not sure how to fix it plz help

    public void QuitGame()
    {
    Debug.Log("You have quit the game");
    if (UnityEditor.EditorApplication.isPlaying == true)
    {
    UnityEditor.EditorApplication.isPlaying = false;
    }
    else
    {
    Application.Quit();
    }
    }
    }

    Another one is
    Error building Player because scripts had compiler errors and there is no errors

    Another one
    Build completed with a result of 'Failed' in 3 seconds (3360 ms)
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)


    and last one
    UnityEditor.BuildPlayerWindow+BuildMethodException: 3 errors
    at UnityEditor.BuildPlayerWindow+DefaultBuildMethods.BuildPlayer (UnityEditor.BuildPlayerOptions options) [0x002c6] in <feb76e495af340bfbdc89fc2ad1b8ae4>:0
    at UnityEditor.BuildPlayerWindow.CallBuildMethods (System.Boolean askForBuildLocation, UnityEditor.BuildOptions defaultBuildOptions) [0x00080] in <feb76e495af340bfbdc89fc2ad1b8ae4>:0
    UnityEngine.GUIUtility:processEvent (int,intptr,bool&)

    Please help me Thanks
     
  2. WarmedxMints

    WarmedxMints

    Joined:
    Feb 6, 2017
    Posts:
    1,035
    The UnityEditor namespace is not available in a build so wrap your code in the UNITY_EDITOR preprocessor.

    Like so
    Code (CSharp):
    1.         public void QuitGame()
    2.         {
    3. #if UNITY_EDITOR
    4.             Debug.Log("You have quit the game");
    5.             if (UnityEditor.EditorApplication.isPlaying == true)
    6.             {
    7.                 UnityEditor.EditorApplication.isPlaying = false;
    8.             }
    9. #else
    10.             Application.Quit();
    11.    
    12. #endif
    13.         }
     
  3. ScottGameDevelopment

    ScottGameDevelopment

    Joined:
    Apr 7, 2020
    Posts:
    42
    How do i check my player for compile errors when it says nothing i went through my player and no script has any errors and no unityeditor
     
  4. ScottGameDevelopment

    ScottGameDevelopment

    Joined:
    Apr 7, 2020
    Posts:
    42
    It change anything same errors but with EditorApplication
     
  5. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    4,193
    As already mentioned, you cannot use any code from the "UnityEditor" namespace in a build. You probably have some "using UnityEditor.XYZ" or something in some of your scripts. Those scripts with can't be used in your game, or you need to conditionally remove the UnityEditor using the same approach mentioned earlier, using #if UNITY_EDITOR.

    Also, as you fix each error, be sure to restate what your new error is.