12

I have the Tiled2Unity plugin. When I begin to build a version of my game in Unity, be it standalone version or anything else,i get the following error, "Error building Player because scripts have compile errors in the editor"

Then it points me to this class

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using UnityEditor;

namespace Tiled2Unity
{
    public class CircleObject : TmxObject
    {
    }
}

Can someone please help me figure out what is the problem?

Programmer
  • 121,791
  • 22
  • 236
  • 328
Letholor
  • 175
  • 1
  • 3
  • 12
  • Hi there. The `using UnityEditor` should be removed. According to the GitHub history of that file that line was never there so not sure how you ended up with it. https://github.com/Seanba/Tiled2Unity/blob/master/unity/Tiled2Unity/Scripts/Runtime/CircleObject.cs – Seanba Dec 06 '22 at 05:27

3 Answers3

20

You cannot build any your script that contains using UnityEditor; or class/API from the UnityEditor namespace. This is why you should put any script that contains any of these in a folder called Editor.

When Unity is building your project, it ignores any script placed in this folder since it considers them as an Editor script or plugin.

You have three choices:

  1. Remove using UnityEditor; from your script.

  2. Place your script in a folder called Editor.

  3. Use Unity's preprocessor directive to determie when not to compile with using UnityEditor;

    You can do that by replacing:

     using UnityEditor;
    

    with

     #if UNITY_EDITOR 
     using UnityEditor;
     #endif 
    

I would go with #2. Create a different script for any Editor stuff and place it in the Editor folder. Note that Unity will not compile any script in this folder when building your project. Scripts in this folder are meant to run in the Editor only.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Programmer
  • 121,791
  • 22
  • 236
  • 328
  • How would I be able to tell if any other parts of my code contain that script? That particular script was imported into Unity via Tiled2Unity. – Letholor Mar 03 '17 at 22:59
  • I don't know what `Tiled2Unity` script is but always try to write your own code instead of importing scripts written by other people. You know this is the problem when you can **run** it in the Editor fine but **cannot** Built it. So, you have to look in other scripts and remove them. If it builds fine then they are all gone! – Programmer Mar 04 '17 at 18:25
1

I was having the same problem however easily found a fix.

Go into every Script you have in that unity project and double check the first lines, the ones which say "Using UnityEngine" and "Unity System Collections". I had only added to these lines with a "Using UnityEngine.UI" however when I was going through ALL my scripts for that project I found that there a few extra ones there that weren't there when I started and I had not added (they added themselves there) , for example there was a "Using System Collections XMP" or something random like that. Simply delete these, save the script and you should be good to go.

I have no idea why they are there and what type of problem they seemed to cause however I can now build my project to android problem free now.

  • So, do you think there might be aN illegaL charactor which might be hidden within the editor. Did you edit them in an external editor or unity? – Neil Jul 30 '20 at 13:02
-1

In Player Setting If You have checked "Use Deterministic Compilation" Then Uncheck this one and Reopen the Unity.

I am Sure Your Problem will be fixed Player>Other Setting > Use Deterministic Compilation (Uncheck)