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
1
Question by Grey_Wolf9 · Aug 15, 2018 at 12:48 AM · freezestuck

Game freezes, cannot see why

Hello allalt text My game freezes randomly, mostly when changing from one level to the next. I cannot tell why this is the case. There are no errors or warnings. This happens when i build the game and when I am testing the game in the Unity editor. It will say unfreeze itself after a few seconds. I have attached one of the level codes and the timer code. I have also attached a picture of how it looks when it freezes.

This is one of the level codes:

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using System.IO.Ports;
 public class Arduino5 : MonoBehaviour
 {
 
     SerialPort sp = new SerialPort("\\\\.\\COM5", 9600);// Com port and the baud rate of the arduino
     Material m_Material;
     GameObject Sphere;
 
 
 
     void Awake()
     {
         Sphere = GameObject.FindWithTag("Player");
         m_Material = GameObject.FindWithTag("Player").GetComponent<Renderer>().material;
     }
     void Start()
     {
         if (!sp.IsOpen)
         { // If the erial port is not open 
             sp.Open(); // Open 
         }
         sp.ReadTimeout = 250; // Timeout for reading 
     }
 
     // Update is called once per frame
     void Update()
     {
         if (sp.IsOpen)
         { // Check to see if the serial port is open 
             try
             {
 
                 string portreading = sp.ReadLine(); // get the string output of the serial port 
                 float amount = int.Parse(portreading);
 
 
 
                 if ((amount > 50f) )
                 {
                     m_Material.color = Color.grey;
                     Renderer _rend = Sphere.GetComponent<Renderer>();
                     Sphere.GetComponent<Renderer>().material = _rend.material;
                     _rend.material.mainTexture = Resources.Load("face4") as Texture;
 
 
                 }
                 else
                 {
                     m_Material.color = Color.white;
                 }
             }
             catch (System.Exception)
             {
 
             }
 
         }
 
     }
 }

This is the timer code:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.UI;
 using UnityEngine.SceneManagement;
 
 public class Timer : MonoBehaviour
 {
     public int timeLeft = 5;
     public Text countdownText;
 
     // Use this for initialization
     void Start()
     {
         StartCoroutine("LoseTime");
     }
 
     // Update is called once per frame
     void Update()
     {
         countdownText.text = ("Time Left = " + timeLeft);
 
         if (timeLeft <= 0)
         {
             StopCoroutine("LoseTime");
             countdownText.text = "Times Up!";
             Invoke("ChangeLevel", 1.0f);
         }
         
     }
 
     IEnumerator LoseTime()
     {
         while (true)
         {
             yield return new WaitForSeconds(1);
             timeLeft--;
         }
     }
     void ChangeLevel()
     {
 
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex + 1);
     }
 
 }
 

freeze.png (187.8 kB)
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 nt314p · Aug 15, 2018 at 12:59 AM 0
Share

The serial port may be beco$$anonymous$$g disconnected between level loads.

avatar image Grey_Wolf9 nt314p · Aug 15, 2018 at 01:03 AM 0
Share

How would I fix that?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by bennett_apps · Aug 15, 2018 at 03:13 AM

Loading a level takes time, especially if your scenes are big.

Comment
Add comment · Show 3 · 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 Grey_Wolf9 · Aug 15, 2018 at 04:31 AM 0
Share

Should the program freeze though?

avatar image RShields Grey_Wolf9 · Aug 15, 2018 at 03:29 PM 0
Share

It'll block. If you want it to not block, you probably want Scene$$anonymous$$anager.LoadSceneAsync

avatar image Grey_Wolf9 RShields · Aug 15, 2018 at 03:48 PM 0
Share

Okay thanks, will look into it

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

91 People are following this question.

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

Related Questions

Building for android freezes at scene 0 Answers

Unity random generator kills programm 2 Answers

Unity remote is freezing? 0 Answers

Game stuck when built... 0 Answers

Unity Keeps Freezing on Play 5 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