Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • 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 Gmodjackass · Jul 01, 2016 at 06:05 AM · freezelidgren

Unity editor freezes but scripts continue to run

I am writing some basic networking code for a game, still just trying the basics. for some reason, my unity editor freezes and won't respond to anything while the code keeps executing as evident by the visual studio pausing in the debugger, it keeps changing and iterating. I assume I have a loop which keeps running and doesn't return control to unity.

here's the main loop of the server code:

 NetIncomingMessage msg;
 void FixedUpdate()
 {
     /*  NETWORKING BLOCK    */
         msg = server.ReadMessage();
         if (msg != null)
         {
             switch (msg.MessageType)
             {
                 case NetIncomingMessageType.Data:
                     {
                         //HANDLE DATA
                         print("server received message " + msg.PeekString());
                         string message = msg.PeekString();
                         UserConnection sender = GetUser(msg.SenderConnection);
                         Rigidbody rb = sender.playerObject.GetComponent<Rigidbody>();
 
                         if (message.Contains("input"))
                         {
                             int index = message.IndexOf("input") + 5; //index of character after input
 
                             while (index < message.Length)
                             {
                                 if (message[index] == 'm') //if movement
                                 {
                                     print("started movement");
                                     index++; //move to field after m
                                     switch (message[index])
                                     {
                                         case '0': //forward
                                             {
                                                 ApplyVelocity(rb, Vector3.forward);
                                                 break;
                                             }
                                         case '1':
                                             {
                                                 ApplyVelocity(rb, Vector3.back);
                                                 break;
                                             }
                                         case '2':
                                             {
                                                 ApplyVelocity(rb, Vector3.left);
                                                 break;
                                             }
                                         case '3':
                                             {
                                                 ApplyVelocity(rb, Vector3.right);
                                                 break;
                                             }
                                         case '4':
                                             {
                                                 ApplyVelocity(rb, Vector3.up);
                                                 break;
                                             }
                                         case '5':
                                             {
                                                 ApplyVelocity(rb, Vector3.down);
                                                 break;
                                             }
                                         case '6':
                                             {
                                                 ApplyBrake(rb);
                                                 break;
                                             }
                                     }
                                     index++;
                                     print("finished movement");
                                 }
                                 else if (message[index] == 'r') //if passed delta rotation
                                 {
                                     print("inside rotation");
                                     index++; //move to field after r
 
                                     int startIndex = index;
                                     int endIndex = startIndex + 1;
                                     while (endIndex < message.Length && message[endIndex] != ',')
                                     {
                                         endIndex++;
                                     }
 
                                     float x;
                                     float.TryParse(message.Substring(startIndex, endIndex - startIndex), out x);
 
                                     startIndex = endIndex + 1;
                                     endIndex += 2;
 
                                     while (endIndex < message.Length && message[endIndex] != ',')
                                     {
                                         endIndex++;
                                     }
 
                                     float y;
                                     float.TryParse(message.Substring(startIndex, endIndex - startIndex), out y);
 
                                     startIndex = endIndex + 1;
                                     endIndex += 2;
 
                                     while (endIndex < message.Length && message[endIndex] != ',')
                                     {
                                         endIndex++;
                                     }
 
                                     float z;
                                     float.TryParse(message.Substring(startIndex, endIndex - startIndex), out z);
 
                                     startIndex = endIndex + 1;
                                     endIndex += 2;
 
                                     while (endIndex < message.Length && message[endIndex] != ',' && message[endIndex] != 'm' && message[endIndex] != 'r') //check that doesn't enter next field
                                     {
                                         endIndex++;
                                     }
 
                                     float w;
                                     float.TryParse(message.Substring(startIndex, endIndex - startIndex), out w);
 
                                     sender.playerObject.transform.rotation *= new Quaternion(x, y, z, w);
                                     print("finished rotation");
                                 }
                                 
                             }
                         }
                         else if (message.Contains("pos"))
                         {
                             //read position and rotation and sets it up for the first time
                             print("started handling first pos");
                             if (sender.IsValid() && sender.canSendPos)
                             {
                                 //parse vector3
                                 int startIndex = 3;
                                 int index = 4;
                                 while (index < message.Length && message[index] != ',')
                                 {
                                     index++;
                                 }
                                 float x;
                                 float.TryParse(message.Substring(startIndex, index - startIndex), out x);
 
                                 float y;
                                 startIndex = index + 1;
                                 index = startIndex + 1;
                                 while (index < message.Length && message[index] != ',')
                                 {
                                     index++;
                                 }
                                 float.TryParse(message.Substring(startIndex, index - startIndex), out y);
 
                                 float z;
                                 startIndex = index + 1;
                                 index = startIndex + 1;
                                 while (index < message.Length && message[index] != ',')
                                 {
                                     index++;
                                 }
                                 float.TryParse(message.Substring(startIndex, index - startIndex), out z);
 
                                 sender.playerObject.transform.position = new Vector3(x, y, z);
 
                                 //parse quaternion
                                 float qX;
                                 startIndex = index + 1;
                                 index = startIndex + 1;
                                 while (index < message.Length && message[index] != ',')
                                 {
                                     index++;
                                 }
                                 float.TryParse(message.Substring(startIndex, index - startIndex), out qX);
 
                                 float qY;
                                 startIndex = index + 1;
                                 index = startIndex + 1;
                                 while (index < message.Length && message[index] != ',')
                                 {
                                     index++;
                                 }
                                 float.TryParse(message.Substring(startIndex, index - startIndex), out qY);
 
                                 float qZ;
                                 startIndex = index + 1;
                                 index = startIndex + 1;
                                 while (index < message.Length && message[index] != ',')
                                 {
                                     index++;
                                 }
                                 float.TryParse(message.Substring(startIndex, index - startIndex), out qZ);
 
                                 float qW;
                                 startIndex = index + 1;
                                 index = startIndex + 1;
                                 while (index < message.Length && message[index] != ',')
                                 {
                                     index++;
                                 }
                                 float.TryParse(message.Substring(startIndex, index - startIndex), out qW);
 
                                 sender.playerObject.transform.rotation = new Quaternion(qX, qY, qZ, qW);
 
                                 sender.canSendPos = false;
                                 print("finished handling first pos");
                             }
                         }
 
                         break;
                     }
 
                 case NetIncomingMessageType.StatusChanged:
                     {
                         switch (msg.SenderConnection.Status)
                         {
                             case NetConnectionStatus.Connected:
                                 {
                                     connectedUsers.Add(new UserConnection(msg.SenderConnection, (GameObject) Instantiate(NetworkedPlayerPrefab, Vector3.zero, Quaternion.Euler(0, 0, 0)))); //spawns the player at 0,0,0 and rotation 0,0,0
                                     print("user conncted to server");
                                     SendString("acceptedConnection");
                                     break;
                                 }
                             case NetConnectionStatus.Disconnected:
                                 {
                                     print("user disconnected from server");
                                     //removes the user from the connection list
                                     NetConnection disconnectingConnection = msg.SenderConnection;
                                     int indexToRemove = -1;
                                     for (int i = 0; i < connectedUsers.Count; i++)
                                     {
                                         if (connectedUsers[i].clientConnection == disconnectingConnection)
                                         {
                                             indexToRemove = i;
                                         }
 
                                         if (indexToRemove != -1)
                                         {
                                             connectedUsers.RemoveAt(indexToRemove);
                                         }
                                     }
                                     break;
                                 }
                         }
                         break;
                     }
 
                 default:
                     print("unhandled error" + msg.MessageType + ", " + msg);
                     break;
             }
             server.Recycle(msg);
         }
     }

Comment
Add comment · Show 1
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 Arkaid · Jul 01, 2016 at 07:36 AM 0
Share

Indeed, that's the case. The first while will only increase index, if it bumps into an "m" or an "r" (line 22, I think?). Otherwise, index will never increase and the loop never ends.

Unity tends to freeze in infinite loops. Check your while ending conditions are met

0 Replies

· Add your reply
  • Sort: 

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Importing from Maya 2 Answers

New User, New Project 0 Answers

unity freezes repeatedly 1 Answer

Unity Freezes on loading (first time user). 2 Answers

Editor freezes while playing audio loop. 1 Answer


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