Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Can't compile my game but, I can play in the Editor

Discussion in 'Editor & General Support' started by MW_Industries, Aug 6, 2020.

  1. MW_Industries

    MW_Industries

    Joined:
    Jan 20, 2018
    Posts:
    62
    Okay, so I've been working on my game for a while and I wanted to show off my game to my next door neighbor but, the problem is that, my game will play in the editor. I play my game fine in the editor and there are no errors.

    I will admit that I accidentally tried to make a copy of my game while Unity was compiling it, which is why I think I'm still getting this error. Recently, I tried copying and pasting a script from this website because, I was being lazy and I wanted to get into procedural generation.

    https://alastaira.wordpress.com/2013/11/14/procedural-terrain-splatmapping/

    The only problem is that, this script contains parts of it that must have been deprecated from the unity engine some time ago as this article is from 2013. I removed the script but, Unity is still asking about updating my project.

    I've cleared the cache, only to find out that Unity had built up about roughly 13GB of data. (And here I was wondering why I was so low on data)

    I've also tried restarting the project by removing everything in the project except the Project Settings and the assets and still no go.

    Finally, I tried updating my project from Unity 2019.4.1 to 2019.4.7 and still no dice. Someone told me I might have to wait about a month before I can compile my game but, I really don't want to wait that long. Does anyone have any advice?

    I just added two different states to the game. It's telling me I have compiler errors yet, I can't find what script they are talking about. There also isn't a place to identify which script they are asking for unless I go through every script I've created for this game and find the error. I'm sure there's an easier way to do this, I just haven't figured it out just yet. Any help, is greatly appreciated. Please and thank you.
     

    Attached Files:

  2. dgoyette

    dgoyette

    Joined:
    Jul 1, 2016
    Posts:
    3,737
    Unfortunately, when Unity gives you build errors, it never seems to tell you the actual error you need to look at. What you'll want to do is open the Unity log file and look at the specific compiler errors it contains. There's a good chance the error has nothing to do with your terrain woes. Very often, the error ends up being that you're trying to use certain namespaces (like Unity.Editor) in a build, which isn't allowed.

    Anyway, look at the log file, and see what it lists for errors. Note that it will also contains warnings, and it's not always super clear what the real error is. But I'd start by looking at the log file and literally searching for "error" or "failed", and see what you find.
     
    MW_Industries likes this.
  3. MW_Industries

    MW_Industries

    Joined:
    Jan 20, 2018
    Posts:
    62
    Last edited: Aug 6, 2020
  4. MW_Industries

    MW_Industries

    Joined:
    Jan 20, 2018
    Posts:
    62

    Okay, so I figured out what my problem was. I accidentally had this namespace in one of my files:

    Code (CSharp):
    1. using UnityEditorInternal;
    This is what stopped it. I see why this was a problem. I found it odd because, Visual Studio didn't tell me anything, the Editor didn't say much either but, I guess it's because Unity doesn't compile games with this namespace inside of it. I assume this namespace is very crucial to the build of the editor as I never used it for anything. I was working on my BattleManager and I may have accidentally entered this namespace when I was moving my laptop around.
     
  5. tsibiski

    tsibiski

    Joined:
    Jul 11, 2016
    Posts:
    328
    That isn't a problem in Visual Studio or in normal editor play because it is a library that exists ONLY when you are using the editor. It supports the editor windows, like the game object hierarchy window, or any other window that appears in the editor. However, when Unity builds an executable file out of the game, the context where any of Unity's editor libraries exist is stripped away, resulting in an error of "what the heck is this using statement, I can't find the resource".

    Go ahead and try adding that back and wrap it in a compile flag.

    Code (CSharp):
    1. #IF UNITY_EDITOR
    2. using UnityEditorInternal;
    3. #endif
    It should not err then. But there isn't a reason or a use (that I can think of) to actually invoke that library in a class outside of an editor script. And editor scripts should go under an "Editor" folder somewhere in the folder structure under the Assets folder. That code will automatically be stripped when generating an exe, apk, ipa etc. So no compiler flags are even needed in that code.

    Avoid mixing game code and editor code though, unless it is code in your game logic that is referenced by the Editor logic. Because there is no situation where Editor logic will be compiled without game code, but the reverse will happen every time you want to execute code outside of the Unity editor.
     
unityunity