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 hotozi · Apr 21, 2013 at 12:25 AM · functionyield

Yield function goes slow sometimes/differently?

im scripting thecnical animation that can be change for a couple of different things...exemple this is a majic casting from the ground...

     var Time:float=0.01;
     var Scaling:float=0.1;
     var Scaling:float=0.1;
 
 function Cast(){
     for(var i=0; i<Multiplie;i++){ 
     transform.localScale.y+=Scaling;
     transform.localPosition.y+=Pos;
     yield WaitForSeconds(Time*Time.deltaTime);
     }
     if(Back)
     {
     yield WaitForSeconds(BackTime);
     for(var iy=0; iy<Multiplie;iy++)
     {
     transform.localScale.y-=Scaling;
     transform.localPosition.y-=Pos;
     yield WaitForSeconds(Time*Time.deltaTime);
     }
     }
 }

the things is that im changing the vars depend of the majic that is casted...and i have a lot...so in my first computer yield run faster than my other one, when i play it on lower graphics and resolution it runing more faster again...when i have a lot of particles(particle emitter mostly)it runing slower but, when i use a mathf.lerp for some animation or even a simple rotation in the update or late update funtion...no matter what happen it runing at the same times and if i have a million of particle exemple...it will do the same but just lagging and skipping some frame around but the yield keep runing out slowly? i cant realy transfert my other animation in the update cuz i cant hold it and its so complicated....is there a way of fixing this?

Comment
Add comment · Show 3
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 Bunny83 · Apr 21, 2013 at 03:31 AM 0
Share

It makes absolutely no sense to multiply the value you pass to WaitForSeconds with Time.deltaTime. It will wait the given amout of seconds. It isn't frame based, it's already time based. But of course like Owen mentioned you can't wait a shorter time than one frame. So if you game runs at 60 fps the shortest time possible is 1/60 of a second == 0.01666 seconds.

avatar image hotozi · Apr 21, 2013 at 04:28 PM 0
Share

i tried both!!!!with and without and its make no difference!!

avatar image cassius · Apr 21, 2013 at 04:35 PM 0
Share

@hotozi @Bunny83 is correct. I don't think it makes much sense to be using the Time.deltaTime in your WaitForSeconds function. That would lead to inconsistent amount of time to wait. What you're doing would somewhat look like this.

  WaitForSeconds(0.000001);
 
  WaitForSeconds(0.000103);
 
  WaitForSeconds(0.000011);
 
  WaitForSeconds(0.000296);
 
  etc, etc..

If you need to change the length of time to wait that's no problem, but I certainly wouldn't do it with Time.deltaTime.

2 Replies

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

Answer by Owen-Reynolds · Apr 21, 2013 at 03:14 AM

Yield fires on the next frame after the time has past, so can't count small numbers. Exs: yielding 0.00001, waits one frame. Yielding 0.0001 tens times in a row will skip 10 frames.

If you have to do delicate timing, maybe pick the final time and yield frames until then:

 while(Time.time<doneTime) {
   do my stuff based on Time.deltaTime
   yield return null; // wait one frame
 }
 snap to final value 

 
Comment
Add comment · Show 1 · 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 hotozi · Apr 21, 2013 at 06:12 AM 0
Share

i get it...but not that munch sorry...can u give me an exemple with my script?

avatar image
1

Answer by Eric5h5 · Apr 21, 2013 at 03:30 AM

If you use "yield WaitForSeconds (Time.deltaTime)" then naturally a faster computer will wait for less time than a slower one, since less time has passed since the last frame. Only use absolute time values in WaitForSeconds, never anything multiplied by deltaTime. WaitForSeconds is already inherently framerate-independent; using Time.deltaTime makes it framerate-dependent.

Comment
Add comment · Show 1 · 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 hotozi · Apr 21, 2013 at 06:11 AM 0
Share

oh ya sorry...forgot to tell u that i used both... wasnt using time.delta time and it were doing the same?

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

15 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

Related Questions

Multiple Cars not working 1 Answer

Coud public variables with same names cause problems? 2 Answers

Yield And Return 2 Answers

Compiling error: [0x00000] in :0 0 Answers

Calling a function after game over to retry 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