• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by c2attech · Feb 09, 2017 at 04:07 PM · build-error

Only one error: Error building Player because scripts have compile errors in the editor

Hey guys,

I looked all over for the answer to this question and just could not find it. I started a new project whose goal was to test out and learn things about networking in Unity. It is currently super simple. It has one empty object with one script on it in C#, plus the default camera and lights. I changed the camera background to black and clear flags to solid color. Below is the script I am using in Visual Studio and the error log I am receiving when trying to build. I am only getting one error and is not telling me exactly what is wrong. I build on the Windows Store Platform, UWP is D3D, SDK is Windows 10 Universal, and debugging Unity C# projects is checked. Any help would be greatly appreciated.

Thanks.

Errors:

Error building Player because scripts have compile errors in the editor

Code:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class NetworkManagerScript : MonoBehaviour {
 
     //Button Positions
     float buttonX = 100;
     float buttonY = 100;
     float buttonW = 250;
     float buttonH = 100;
     string typeName = "Super Unique Network Type Name";
     string gameName = "Network Practice";
     private HostData[] hostList;
 
     //Starts the server
     private void StartServer()
     {
         Network.InitializeServer(2, 25001, !Network.HavePublicAddress());
         MasterServer.RegisterHost(typeName, gameName, "Learning Network Skills");
     }
 
     //Gets called when server is initialized
     void OnServerInitialized()
     {
         Debug.Log("Server Initializied");
     }
 
     //GUI
     void OnGUI()
     {
         //If you aren't connected to the server...
         if (!Network.isClient && !Network.isServer)
         {
             //Creates a button and if you click it...
             if (GUI.Button(new Rect(buttonX, buttonY, buttonW, buttonH), "Start Server"))
             {
                 StartServer();
                 Debug.Log("It worked!");
             }
 
             //Creates button and if you click it...
             if (GUI.Button(new Rect(buttonX, buttonY + 150, buttonW, buttonH), "Refresh Hosts"))
             {
                 RefreshHostList();
                 Debug.Log("Refreshing...");
             }
 
             //If the request is not empty...
             if (hostList != null)
             {
                 //For each guy in the host list...
                 for (int i = 0; i < hostList.Length; i++)
                 {
                     //Creates a button and if you click it...
                     if (GUI.Button(new Rect(4 * buttonX, buttonY + (110 * i), buttonW + 50, buttonH), hostList[i].gameName))
                     {
                         JoinServer(hostList[i]);
                     }
                 }
             }
         }
     }
 
     //Requests host data
     private void RefreshHostList()
     {
         MasterServer.RequestHostList(typeName);
     }
 
     //If it finds the host data from the above function, it stores it in hostList
     void OnMasterServerEvent(MasterServerEvent msEvent)
     {
         if (msEvent == MasterServerEvent.HostListReceived)
             hostList = MasterServer.PollHostList();
     }
 
     //Joins the server
     private void JoinServer(HostData hostData)
     {
         Network.Connect(hostData);
     }
 
     //Called when server is joined
     void OnConnectedToServer()
     {
         Debug.Log("Server Joined");
     }
 
 }
 
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image tanoshimi · Feb 09, 2017 at 08:14 PM 1
Share

And that file is called Network$$anonymous$$anagerScript.cs, right?

avatar image c2attech tanoshimi · Feb 10, 2017 at 02:41 PM 0
Share

Sorry, I did not see this comment. Yes, it is called that.

3 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by MarshallN · Feb 09, 2017 at 07:16 PM

You didn't include

using UnityEngine.Networking;

at the start of your code. Your script doesn't know what functions you're trying to call! Try that first, let me know if it still fails.

Comment
Add comment · Show 12 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image c2attech · Feb 09, 2017 at 08:01 PM 0
Share

Hi $$anonymous$$arshallN,

I added that line and it changed nothing. Same errors. Do you need that line? I do not know a whole lot about the using statements, but does "using UnityEngine;" not include all of those underlying function libraries?

Thanks

avatar image MarshallN c2attech · Feb 09, 2017 at 08:21 PM 0
Share

It does include them, but requires a library call at the start of the function call (i.e., UnityEngine.Networking.SomeFunction() ins$$anonymous$$d of just SomeFunction()).

Next thing I would try would be to set build target to just PC/$$anonymous$$ac/Linux Standalone; if it works for that and not for the Windows Store build target, that refines your error.

avatar image c2attech MarshallN · Feb 09, 2017 at 08:50 PM 0
Share

$$anonymous$$arshallN,

It does build if I set the build settings to PC/Linux/$$anonymous$$ac standalone. So what does that mean then? Do you know how to get it to build for windows?

Thanks

Show more comments
avatar image tanoshimi c2attech · Feb 10, 2017 at 01:56 PM 0
Share

So you're saying a script containing only the following causes the error?

  private void StartServer()
  {
    ;
  }
avatar image c2attech tanoshimi · Feb 10, 2017 at 02:39 PM 0
Share

Initially it did (without the semi-colon), but now it works fine so long as I comment out the hostData declaration above it. And now (for some reason) it is telling me the namesace or type HostData[] cannot be found. $$anonymous$$y* above comments are a bit more detailed if you see them.

avatar image c2attech · Feb 09, 2017 at 08:03 PM 0
Share

Also, to be sure. It said someone replied on here asking if there were any unwanted scripts in my project. There is only the one script posted above. I am sure of that.

avatar image
0

Answer by Magic73 · Feb 16, 2017 at 02:00 PM

I have the same issue...

error CS0246: The type or namespace name 'HostData' could not be found (are you missing a using directive or an assembly reference?)

I'm trying to build a UWP app.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Big-Ed · Sep 03, 2017 at 04:21 PM

For me the error was because some how the following using was included in one of my C# scripts.

using UnityEditorInternal;

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Why can't I build Web Player in Unity while I have no problems with building standalone versions? 2 Answers

How can I stop the variable values reverting to its default values after being built? 1 Answer

Can't build to iOS, but web and OS X builds fine 1 Answer

Xcode 5 headache 1 Answer

Unity: Cannot find Android Device 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges