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 K-Skanz · Oct 14, 2019 at 11:00 PM · loadinglagloading screen

Reloading the same screen taking minutes. But loading from another scene is instant.

I have a strange behavior occurring in my game, the first load from another scene is less than a second, but if the player dies, it trigger a SceneManager.LoadScene("same scene"), and now the loading takes like 5 minutes, here an Image to illustrate:

alt text

I tried to load another scene that loads the main game again, but it just didn't work:

alt text

Here is the trigger of the game over:

 IEnumerator Death()
     {
         float ElapsedTime = 0;
         while (Time.timeScale > 0)
         {
             ElapsedTime += Time.fixedDeltaTime/5;
             Time.timeScale = Mathf.Clamp01(1f - ElapsedTime);
             if (Custom)
             {
                 GameObject.Find("Difficulty_Script").GetComponent<AudioSource>().volume = Mathf.Clamp01(1f - ElapsedTime);
             }
             else
             {
                 Music.volume = Mathf.Clamp01(1f - ElapsedTime);
             }            
             HUD.alpha = Mathf.Clamp01(1f - (ElapsedTime * 2));
             Blur.SetFloat("_Size", ElapsedTime * 2);
 
             yield return null;
         }
 
         ElapsedTime = 0;
 
         while (ElapsedTime < 1)
         {
             ElapsedTime += Time.fixedDeltaTime/5;
             GameOver.color = new Color(1,1,1, Mathf.Clamp01(0f + ElapsedTime));
             yield return null;
         }
 
         ElapsedTime = 0;
 
         while (ElapsedTime < 1)
         {
             ElapsedTime += Time.fixedDeltaTime /5;
             Fade.color = new Color(0, 0, 0, Mathf.Clamp01(0f + ElapsedTime));
             yield return null;
         }
         Time.timeScale = 1;
         SceneManager.LoadScene("Reloading");
                         
         yield return null;
     }

(Ignore all the Mathf, I'll change it later :P)

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

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Eno-Khaon · Oct 15, 2019 at 02:21 AM

Time.fixedDeltaTime is the timestep used for processing physics in FixedUpdate(). In order for the physics interactions to remain consistent, the physics rate must scale with Time.timeScale.

What you're probably looking for is Time.unscaledDeltaTime.

When you die, you're slowing down time over the course of ~5 seconds... However, that number of seconds is increasing with every new frame as you reduce the timeScale. If the elapsedTime is 0.95, for example, then your timeScale is 0.05 and Time.fixedDeltaTime should be reporting 0.001 (assuming the baseline 50 physics updates per second). The more time passes, the more time will be necessary to reach the end of the timer when you reset the scene.

Quite frankly, considering the loops you're using, I think I'm more amazed that it actually *CAN* reach the end of all that. Is Time.fixedDeltaTime not actually reporting zero eventually?

That's where Time.unscaledDeltaTime comes in. It's specifically intended to ignore any changes to Time.timeScale so that this sort of thing won't happen.

Comment
Add comment · Show 4 · 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 K-Skanz · Oct 15, 2019 at 02:40 AM 0
Share

I tried with Time.unscaledDeltaTime, but it's just the same, the code doesn't have a problem to reach Scene$$anonymous$$anager.LoadScene("Reloading"), the problem is when it starts loading, I put a debug.log("Hi") right before Scene$$anonymous$$anager.LoadScene("Reloading"), and he only print after 5 $$anonymous$$ and with like 250 "Hi".

avatar image Eno-Khaon K-Skanz · Oct 15, 2019 at 02:46 AM 0
Share

If it's printing that ~250 times, what's your logic for calling the Death() function?

That makes it sound like it's queued up a scene load ~250 times simultaneously and is actually willing to go through with it.

avatar image K-Skanz Eno-Khaon · Oct 15, 2019 at 03:03 AM 1
Share

I'm a shame as Programmer xD

 if (Player.HP <= 0 && !DeathBlock)
         {
             DeathBlock = true; // that was false
             StartCoroutine(Death());
             StartCoroutine(BlurFade());
         }

thank you very much and sorry

Show more comments

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

113 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 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

loading a scene seems to be slower 0 Answers

Do we need pro version for loading progress in unity 5 ? 0 Answers

Loading Screens are confusing 0 Answers

How do I code just a Loading scene with text and pictures in unity3d c# 2 Answers

Is there a perferred method for handling scene loading? 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