Cannot Build Project

Issue #4 resolved
Former user created an issue

When I try to build the project I get the following error: "Error Building Player because scripts have compile errors in the editor". I am running 5.6.3p2

To reproduce the error simply create a new empty scene and import the Uduino asset and save the scene. Even in this simplest possible case you will get the error when you try building the project.

Comments (6)

  1. Marc Teys repo owner

    I could not reproduce the errror by importing Uduino asset. Did you run the initial configuration and/or manually set the .NET API compatibility ? (Set the API Compatibility level to .NET 2.0 (and not .Net 2.0 Subset). This setting is located under Edit\Project settings\Player. )

  2. Albert

    I have tried both and am still unable to build. I have also tried when the board is connected and disconnected, when the Uduino asset is placed into the scene, and when it is not, and nearly any other combination. When you tried reproducing the error, were you using the latest Unity 5.6.3p2?

    There is another message in the console, right before the one mentioned above, that I did not notice previously:

    " Assets/Uduino/Scripts/UduinoDevice.cs(2,7): error CS0246: The type or namespace name `UnityEditor' could not be found. Are you missing an assembly reference?"

    "Error building Player because scripts had compiler errors"

  3. Marc Teys repo owner

    Oh I see, in the last update I added a reference to UnityEditor without adding the flag for building.

    You can edit the script UduinoDevice.cs as following:

    using UnityEngine;
    #if UNITY_EDITOR
    using UnityEditor;
    #endif
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    
    namespace Uduino
    {
        public class UduinoDevice : SerialArduino
        {
            public string name {
                get
                {
                    return _name;
                } set
                {
                    if (_name == "")
                        _name = value;
                }
            }
            private string _name = "";
    
            public int boardType = 0;
    
            public bool continuousRead = false;
            public string read = null;
            public string lastRead = null;
            public string lastWrite = null;
            private Dictionary<string, List<string>> bundles = new Dictionary<string, List<string>>();
    
            public System.Action<string> callback = null;
    
            public UduinoDevice(string port, int baudrate = 9600, int readTimeout = 100, int writeTimeout = 100, int boardType = 0) : base(port, baudrate)
            {
                this.readTimeout = readTimeout;
                this.writeTimeout = writeTimeout;
                this.boardType = boardType;
            }
    
            /// <summary>
            /// Add a message to the bundle
            /// </summary>
            /// <param name="message">Message to send</param>
            /// <param name="bundle">Bundle Name</param>
            public void AddToBundle( string message , string bundle)
            {
                List<string> existing;
                if (!bundles.TryGetValue(bundle, out existing))
                {
                    existing = new List<string>();
                    bundles[bundle] = existing;
                }
                existing.Add("," + message);
              //  Log.Debug("Message <color=#4CAF50>" + message + "</color> added to the bundle " + bundle);
            }
    
            /// <summary>
            /// Send a Bundle to the arduino
            /// </summary>
            /// <param name="bundleName">Name of the bundle to send</param>
            public void SendBundle(string bundleName)
            {
                List<string> bundleValues;
                if (bundles.TryGetValue(bundleName, out bundleValues))
                {
                    string fullMessage = "b " + bundleValues.Count;
    
                    if (bundleValues.Count == 1 ) // If there is one message
                    {
                        string message = bundleValues[0].Substring(1, bundleValues[0].Length - 1);
                        if (message.Contains("r")) ReadFromArduino(message);
                        else WriteToArduino(message);
                        return;
                    }
    
                    for (int i = 0; i < bundleValues.Count; i++)
                        fullMessage += bundleValues[i];
    
                    if (fullMessage.Contains("r")) ReadFromArduino(fullMessage);
                    else WriteToArduino(fullMessage);
    
                    if (fullMessage.Length >= 120)  /// TODO : Max Length, matching avec arduino
                        Log.Warning("The bundle message is too big. Try to not send too many messages or increase UDUINOBUFFER in Uduino library.");
    
                    bundles.Remove(bundleName);
                }
                else
                {
                    if(bundleName != "init")
                        Log.Info("You are tring to send the bundle \"" + bundleName + "\" but it seems that it's empty.");
                }
            }
    
            public void SendAllBundles()
            {
                Log.Debug("Send all bundles");
                List<string> bundleNames = new List<string>(bundles.Keys);
                foreach (string key in bundleNames)
                    SendBundle(key);
            }
    
            public override void WritingSuccess(string message)
            {
                lastWrite = message;
            }
    
            public override void ReadingSuccess(string message)
            {
                if(lastRead == null) 
                {
                    lastRead = message;
                    return; // If the previous message was empty it's meaning that it was the first one; so we don't transmit it. 
                }
                else 
                    lastRead = message;
    
                if (UduinoManager.Instance)
                {
                    UduinoManager.Instance.InvokeAsync(() =>
                    {
                        if (message.Split(' ')[0] == "uduinoIdentity")
                            return;
    
                        if (callback != null)
                            callback(message);
                        UduinoManager.Instance.TriggerEvent(message, _name);
                        #if UNITY_EDITOR
                        if (Application.isPlaying) EditorUtility.SetDirty(UduinoManager.Instance);
                        #endif
                    });
                } else if(!Application.isPlaying && callback != null) //if it's the editor
                    callback(message);
            }
        }
    }
    
  4. Log in to comment