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 /
  • Help Room /
This question was closed Jun 21, 2016 at 02:50 PM by kemar for the following reason:

Problem is not reproducible or outdated

avatar image
0
Question by kemar · Jun 21, 2016 at 09:40 AM · unity 5freeze

Unity Freezing

Hello, I have a 'for' loop in my coroutine who cause a Unity freezing. I've tried to fix it, but I don't understand... Anybody has an idea why the loop provokes a freeze?

Thanks !

The coroutine :

   public static IEnumerator ScoreCountTo(int score, int target)
         {
             Debug.Log("Score Count ");
             int duration = 3;
             int start = score;
             float progress = 0f;
             string str = LanguageManager.Instance.readValue("txt_score");
 
             updateField(0, str + score);
 
             for (float timer = 0; timer < duration; timer += Time.deltaTime )
             {
                 Debug.Log("Timer " + timer + " Time.deltaTime " + Time.deltaTime);
                // progress = timer / duration;
                 //score = (int)Mathf.Lerp(start, target, progress);
                 //updateField(0, str + score);
                 yield return null;
             }
             updateField(0, str + target);
             MainSingleton.Instance.stopTime();
         }


Last result before the freeze : alt text

sans-titre.png (4.7 kB)
Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0

Answer by UsmanAbbasi · Jun 21, 2016 at 10:14 AM

Note: Whenever something takes too long e.g. loops, etc. it causes unity to freeze.

Now coming to your answer:

Time.deltatime = 0.007 as shown in the screenshot. Lets consider it average Delta time. Which means you are adding 0.007 in your "timer" variable.

3 / 0.007 = 428.5 which means this loop will take 428.5 frames to complete. If frame rate per second is lets say 40, then it will take 428/40 = 10.7 seconds to complete this loop.

So my guess is that your loop is taking so long which makes unity freeze.

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

Follow this Question

Answers Answers and Comments

90 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

Related Questions

Why Unity 5 freeze when build sharedassets0.assets ? 15 Answers

After opening or creating project , unity editor window won't show up 0 Answers

[HELP URGENT] Resolving dependencies. 0 Answers

unity 3d freeze 0 Answers

Unity freezes after editing code (Visual Studio) 0 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