Search Unity

I can't build my game

Discussion in '2D' started by Zunooo, Jan 4, 2020.

Thread Status:
Not open for further replies.
  1. Zunooo

    Zunooo

    Joined:
    Sep 3, 2019
    Posts:
    12
    Here's the message what i get: cannot build player while editor is importing assets or compiling scripts
    I'm not importing or compiling anything. I already tried to restart Unity, but didn't worked. WHvT.png
    Package manager: spMH.png
     
    PlayCreatively and BrainSlugs83 like this.
  2. Antypodish

    Antypodish

    Joined:
    Apr 29, 2014
    Posts:
    10,778
    Show us console errors.
     
  3. Zunooo

    Zunooo

    Joined:
    Sep 3, 2019
    Posts:
    12
    Hello dude, i already solved it.
     
    wojtuswojti likes this.
  4. patmaric

    patmaric

    Joined:
    Dec 5, 2019
    Posts:
    15
    Well, what was it? I have the same issue.
     
  5. patmaric

    patmaric

    Joined:
    Dec 5, 2019
    Posts:
    15
    Never mind, I fount it, too. I had using UnityEditor in my script and removed it. Now I can build.
     
    nawatng, JoJo777890, GaGI7 and 10 others like this.
  6. SHELTOM

    SHELTOM

    Joined:
    Nov 13, 2019
    Posts:
    1
    I have the same issue.
     
  7. AXIN-DESIGN

    AXIN-DESIGN

    Joined:
    Mar 13, 2020
    Posts:
    1
    check your script, which one had "using UnityEditor", delete it.
     
    EmberQWQ, JoJo777890, misosry and 9 others like this.
  8. laithbarakat2002

    laithbarakat2002

    Joined:
    Apr 5, 2020
    Posts:
    2
    guys i have the same issue and really confused what to do.
     
    DerDomme and MWilliams_XR like this.
  9. RadioactivPankakez

    RadioactivPankakez

    Joined:
    Jun 20, 2018
    Posts:
    2
    Was this what was in your log?
    Build completed with a result of 'Failed'
    UnityEngine.GUIUtility: ProcessEvent(Int32, IntPtr)
     
    gaming123 and Ertra like this.
  10. RadioactivPankakez

    RadioactivPankakez

    Joined:
    Jun 20, 2018
    Posts:
    2
    Look through all of the script you can. At the top of one there may be a line that says, "using UnityEditor;" Erase that and fix errors that it may cause.

    I don't know if there is a search function that will let you look for that, but if there is utilize that. I downloaded a pack that was actually from Unity themselves and the thing had the "using UnityEditor;" in it.
     
    JoJo777890 and anmar_2101 like this.
  11. Irtaza-2009

    Irtaza-2009

    Joined:
    May 15, 2020
    Posts:
    2
    I have the same issue
     
  12. Irtaza-2009

    Irtaza-2009

    Joined:
    May 15, 2020
    Posts:
    2
    how do you check your scripts
     
  13. drakeerv

    drakeerv

    Joined:
    May 12, 2020
    Posts:
    2
    I checked all my scripts and it still does not work
     
  14. JoaoGuilhermeRodrigues

    JoaoGuilhermeRodrigues

    Joined:
    May 28, 2020
    Posts:
    1
    My scripts say using UnityEngine. Is that the same as unityeditor?
     
  15. X_Computations

    X_Computations

    Joined:
    Sep 27, 2019
    Posts:
    1
    If you are using 3rd party tools like snaps tools which use unityeditor then delete it for once you can import again. It works for me
     
  16. alaagame2020

    alaagame2020

    Joined:
    Jun 5, 2020
    Posts:
    4
    Which script I have to check? the script uneditable!
     
  17. alaagame2020

    alaagame2020

    Joined:
    Jun 5, 2020
    Posts:
    4
    Hi, I deleted all of them but I still cannot build! any solutions?
     
  18. alaagame2020

    alaagame2020

    Joined:
    Jun 5, 2020
    Posts:
    4
    Any in video solution, please?
     
  19. briceouoba

    briceouoba

    Joined:
    Jun 5, 2020
    Posts:
    1
    go to the Project winndow> Assets folder> Scripts
    hope that helps
     
    Andrewski0117 likes this.
  20. asem0525

    asem0525

    Joined:
    Jun 15, 2020
    Posts:
    1
    I need help with same issue guys, please.
    I have just installed Unity and following the Kart tutorial created my first game, I wanted to try it on my Android phone6 but when I click Build and Run, it shows this:
     

    Attached Files:

  21. cyclSunity

    cyclSunity

    Joined:
    Jun 10, 2020
    Posts:
    123
    I know you figured it out, but did you have a JDK (Java Development Kit) ?
     
  22. nnurgle

    nnurgle

    Joined:
    Nov 22, 2014
    Posts:
    12
    having the same issue, used find in files to locate all using UnityEditor. In all cases they were under an Editor folder, so all should be ok. Just in case I added "
    #if UNITY_EDITOR" before the using line and #endif at the end of the file. Still having the same error.

    Any other things that can cause this msg?
     
    jonny4th, octav88 and Madsen87 like this.
  23. masmear

    masmear

    Joined:
    Apr 29, 2020
    Posts:
    2
    I got the solution that unity tell you there is some scripts has errors you should delete it and delete the GI cash.. that's helped me
     
  24. MlleBun

    MlleBun

    Joined:
    Sep 19, 2017
    Posts:
    163
    Moreover, if you still need using UnityEditor :

    Code (CSharp):
    1. #if UNITY_EDITOR
    2.  
    3. using UnityEditor;
    4.  
    5. #endif
    or put the script containing using UnityEditor in a folder named Editor. I usually put a parent folder (with the script name for ex) in which I create the Editor folder at the root of Assets.
     
    Tm013, kikeUY, BrainSlugs83 and 3 others like this.
  25. RyzenTX

    RyzenTX

    Joined:
    Jul 6, 2020
    Posts:
    1
    How did you fix it
     
  26. Fox_GAMING

    Fox_GAMING

    Joined:
    May 7, 2018
    Posts:
    12
    I have that, have you found a way to fix it?

    EDIT: Nevermind, I fixed it. I just needed to remove using UnityEngine.System.Security.Policy.
     
    Last edited: Jul 26, 2020
    Xav314 likes this.
  27. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    same problem here, it does not specify which scripts are to blame, after like 20 yrs of dev they havent done that :(
     
    tmendez and DeidreReay like this.
  28. DeidreReay

    DeidreReay

    Joined:
    Oct 28, 2019
    Posts:
    50
    Seriously.. Is it bolt that is doing this??
     
  29. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    im not even using bolt, it could be literally anything, but unity see fit not to give us a clue for some reason
     
  30. zarishareej

    zarishareej

    Joined:
    Sep 3, 2020
    Posts:
    1
    Remove every line from every script start with "using" which are not used in you project but by default unity write it.

    Like from picuter
    Using System.collections;
    Using System. Collection. Generic;
    etc.
    Should remove

    These will dim in color from other
    Namespaces
     

    Attached Files:

  31. Neltor

    Neltor

    Joined:
    Sep 9, 2015
    Posts:
    5
    If you are on Windows you can use PowerShell to find out what files contain "using UnityEditor". Open PowerShell and go to your projects Asset folder and type the following command:

    Get-ChildItem -Recurse | Select-String "using UnityEditor" -List | Select Path

    That should give you a complete list of all the files that are using it.
     
    FishPyramid and radiantboy like this.
  32. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    thanks so when it fails it does not report that it failed due to "using UnityEditor" or report the file that is using it ?
     
  33. Neltor

    Neltor

    Joined:
    Sep 9, 2015
    Posts:
    5
    Correct, it only gives the "cannot build player while editor is importing assets or compiling scripts" message.
     
    radiantboy likes this.
  34. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Hey great thanks! I will sort that out asap!.. I think thye need to fix that tho :)
     
  35. MarcusJT

    MarcusJT

    Joined:
    Oct 3, 2019
    Posts:
    4
    Had this issue after using a free asset for a fireball.
    Had built ok yesterday so that was the obvious suspect.

    Removed this asset and built ok.
    Thanks for the help.

    And yes it was using Unity.Editor
     
    radiantboy likes this.
  36. deekshitaverma

    deekshitaverma

    Joined:
    Jun 30, 2020
    Posts:
    1
    I tried both it didn't help
     
  37. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    did it still fail with no error? also did u search the code files to make sure all references to nityeditor are enclosed in preprocessors?
     
  38. Adisak

    Adisak

    Joined:
    Feb 21, 2014
    Posts:
    1
    You need to put #if UNITY_EDITOR and #endif in every files that using UnityEditor and also put them inside the class body. Please see the example below.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. #if UNITY_EDITOR
    4. using UnityEditor;
    5. #endif
    6.  
    7. namespace PolyPerfect
    8. {
    9.     [CustomEditor(typeof(Common_WanderManager))]
    10.     public class Common_WanderManagerEditor : Editor
    11.     {
    12. #if UNITY_EDITOR
    13.         public override void OnInspectorGUI()
    14.         {
    15.             //Load a Texture (Assets/Resources/Textures/texture01.png)
    16.             var mainTexture = Resources.Load<Texture2D>("ManagerLogo");
    17.             GUILayout.BeginHorizontal();
    18.             if (GUILayout.Button(mainTexture))
    19.             {
    20.                 Application.OpenURL("https://assetstore.unity.com/?q=Polyperfect&orderBy=0");
    21.             }
    22.             GUILayout.EndHorizontal();
    23.  
    24.             Common_WanderManager Manager = (Common_WanderManager)target;
    25.  
    26.             if (!Application.isPlaying)
    27.             {
    28.                 base.OnInspectorGUI();
    29.                 return;
    30.             }
    31.  
    32.             GUILayout.Space(10);
    33.  
    34.             Manager.PeaceTime = EditorGUILayout.Toggle("Peace Time", Manager.PeaceTime);
    35.  
    36.             GUILayout.Space(5);
    37.  
    38.            if (GUILayout.Button("Kill 'Em All"))
    39.             {
    40.                 Manager.Nuke();
    41.             }
    42.         }
    43.     }
    44. #endif
    45. }
    46. }
     
    radiantboy and MJunior1989 like this.
  39. NYX128

    NYX128

    Joined:
    Aug 2, 2020
    Posts:
    8
    Thanks a lot i had using UnityEditor.graphview in my controlscript so erasing that helped it
     
  40. MathMaster

    MathMaster

    Joined:
    Apr 28, 2015
    Posts:
    1
    THANKS YOU SOOO MUCH! IT WORKS...
     
  41. FireAshen

    FireAshen

    Joined:
    Dec 25, 2020
    Posts:
    5

    Hey Adisak, thx for your infomation. I have imported some plugins to my project. I found some files of plugins outside of the folder "Editor" but the codes"using UnityEditor;" of which is inside the "#if UNITY_EDITOR". If I move those files to the folder "Editor" it may cause some erros Missing references. So I dont know what should I do for my problems is better.....
     
  42. FireAshen

    FireAshen

    Joined:
    Dec 25, 2020
    Posts:
    5
    Hey, MlleBun, I have imported some plugins into my project, and almost all files have codes "using UnityEditor" are inside of the folder "Editor" , and others are used codes "#if UNITY_EDITOR" for them. I tried to remove the codes "using UnityEditor" of the scripts that outside of the folder "Editor", but it still not work for me, if there any other ideas? thx for your help.
     
  43. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    If you search all .cs files for these things and wrap them in #if UNITY_EDITOR, it should work

    using UnityEditor
    [ContextMenu
    OnDrawGizmos

    if you still have issues sometimes you get a clue from the editor log
    at C:\Users\user\AppData\Local\Unity\Editor

    I went through this recently and it finally worked!...

    On windows I use "Agent Ransack" to do my searching, very useful.
     
    Last edited: Jan 8, 2021
  44. reimplosion

    reimplosion

    Joined:
    Jan 18, 2021
    Posts:
    1
    Hi,guys. I met the same issues after I followed the share instruction of the offical Karting Micro Game. I have tried deleting the headline "using UnityEditor" and relevant codeline, but it still can't work. Is there any other idea to solve this question?
     
  45. FireAshen

    FireAshen

    Joined:
    Dec 25, 2020
    Posts:
    5

    Thx for info. I will try it.~~~
     
  46. Hasan_Green

    Hasan_Green

    Joined:
    Oct 15, 2020
    Posts:
    2
    Handles.jpg I met the same issues but I already solved it. it's not a problem about "UNITY_EDITOR" in my case I delete (Handles.Label in OnDrawGizmos) "Handles.Label" it's custom 3D GUI controls and drawing in the scene view. I make text in scene view.
     
  47. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    you need to ifdef the entire onDrawGizmos() method
     
  48. HellsHand

    HellsHand

    Joined:
    Dec 31, 2013
    Posts:
    3
    Apparently there is another cause to this issue. If you are inheriting from another script that is using UnityEngine, Visual Studio will tell you that the
    using UnityEngine
    directive is unnecessary. This may normally be true, except if you happen to be using
    #if !Unity_Editor
    in your script. Everything up to
    #endif
    that is part of UnityEngine is seen as not existing.
    A small example:
    Code (CSharp):
    1. #if !UNITY_EDITOR
    2.         if(Input.GetKeyDown(KeyCode.Escape))
    3.         {
    4.             Application.Quit();
    5.         }
    6. #endif
    Without
    using UnityEngine
    this code throws errors saying that Input, KeyCode and Application do not exist in the current context and stops the build with the 'cannot build player while editor is importing assets or compiling scripts' message in the build window.
     
    radiantboy likes this.
  49. radiantboy

    radiantboy

    Joined:
    Nov 21, 2012
    Posts:
    1,633
    Wow, well at least it sounds like their error messages have improved to actually tell you what is the issue.
     
  50. BinaryByron

    BinaryByron

    Joined:
    Sep 16, 2016
    Posts:
    12
    I ran into this issue today. Builds would just stop, if I did it from `Build and Run` I'd just get "cannot build player while the editor is importing...". No errors in the console.

    I opened up the editor.log and low and behold, one of my `#if UNITY_EDITOR` defines was consuming a `}`. The moral of the story is to always check the logs! https://docs.unity3d.com/Manual/LogFiles.html

    Here's a snippet:

    Code (CSharp):
    1.  
    2. ##### ExitCode
    3. 1
    4. ##### Output
    5. Assets/RowdyRobot/Scripts/Persistence/SerializableScriptableObject.cs(25,2): error CS1513: } expected
    6. *** Tundra build failed (0.65 seconds), 79 items updated, 540 evaluated
    7. Assets/RowdyRobot/Scripts/Persistence/SerializableScriptableObject.cs(25,2): error CS1513: } expected
    8.  
    9. [ScriptCompilation] Requested script compilation because: Recompiling scripts for editor because player build failed.
    10. Error building Player because scripts had compiler errors
    11.  
    12.  
     
    joymepls and hhoffren like this.
Thread Status:
Not open for further replies.