Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Atnas1010 · Nov 13, 2010 at 07:54 AM · yieldwaitforsecondsnetworkview

yield WaitForSeconds waits for too long.

When I run an empty project with this script attached to the main camera, the lag counter increments. The fixed one does not. I have a quadcore, so I'd say the processing power should be sufficient.

var currTime : float; var lag : int;

var currFixedTime : float; var fixedLag : int; function Start() { Time.fixedDeltaTime=0.05; while(true) { if (Time.time-currTime>0.1) lag +=1; currTime = Time.time; yield WaitForSeconds(0.05); } }

function FixedUpdate() { if (Time.time - currFixedTime > 0.1) fixedLag +=1; currFixedTime = Time.time; }

function OnGUI() { GUILayout.Label("Time: " + currTime); GUILayout.Label("Lag: " + lag); GUILayout.Label("Fixed: " + fixedLag); }

I assume I get the lags because WaitForSeconds is somehow tied into the framerate. How can I get the behaviour I'm getting from FixedUpdate, without using FixedUpdate? (Still want my physics to be calculated 50 times per second)

-Bonus Question:

Are NetworkViews synchronization lagging in the same way as the WaitForSeconds?

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

2 Replies

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

Answer by Mike 3 · Nov 13, 2010 at 10:53 AM

It could well be that you're using a large amount of memory, and every 20 seconds or so it's hitting a Garbage Collection.

Alternatively, it could be caused by an already low frame rate if you're trying to render too much.

Hard to tell without more information though, but it's probably a mixture of both.

Comment
Add comment · Show 6 · 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 Atnas1010 · Nov 13, 2010 at 12:26 PM 0
Share

The project is just the script I posted, and running on the default main camera. So not allocating any memory (other than OnGUI). The framerate is fine, because the project doesn't contain anything. The lags also occur in the standalone player, and somewhat in the editor (I set them to run in background and just let them run). What more info would you like?

avatar image Mike 3 · Nov 13, 2010 at 01:32 PM 0
Share

In that case, really not sure. Try make a second lag counter, which you increment if Time.deltaTime (in Update) is greater than 0.1, see how the actual delta stacks up against your calculated one

avatar image Atnas1010 · Nov 13, 2010 at 03:24 PM 0
Share

The second lag counter got me thinking. I set my fixed update rate to 0,05, and in the fixed update loop tried doing the same thing as in the while(true) loop. That doesn't lag. Also, the counter you suggested gives approx the same as my counter. I also found the max deltaTime to be ~0.2 so apparently there are some lags. Edited my question, to include this.

avatar image Mike 3 · Nov 13, 2010 at 05:40 PM 0
Share

FixedUpdate is called multiple times a frame to catch up, so isn't actually being called every 0.05s per se. What you could do is use InvokeRepeating("FunctionName", 0.05, 0.05); to have a constantly called function, which should give the same results as FixedUpdate

avatar image boymeetsrobot · Nov 13, 2010 at 10:48 PM 0
Share

Of the three methods InvokeRepeating, WaitForSeconds and WaitForFixedUpdate I find WaitForSeconds to give the most consistent ti$$anonymous$$gs.

Show more comments
avatar image
0

Answer by boymeetsrobot · Nov 13, 2010 at 08:35 AM

Try removing the if statement in the while loop and just run the yield.

Comment
Add comment · Show 2 · 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 Atnas1010 · Nov 13, 2010 at 09:37 AM 0
Share

The result is the same when I put the if statement into Update.

avatar image boymeetsrobot · Nov 13, 2010 at 10:49 PM 0
Share

Try using WaitForFixedUpdate. Regarding your if statement, I would not use it at all if possible. Doing my own tests with Time.time with a similar method was less consistent for me.

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

No one has followed this question yet.

Related Questions

Why Is yield return new WaitForSeconds() not working 2 Answers

Understanding yield inside a for or a while loop 2 Answers

About removing the backlight of a button after a set of time 2 Answers

Yield waitforseconds not consistent for animation-unity2D 0 Answers

Script gets stuck on WaitForSeconds() 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