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 Grant 1 · Jun 19, 2010 at 11:07 AM · updateyieldwhilerecursion

A while type statement in the Update function, Yield?

Alright, what I am trying to do is grab all colliders for 5 secs. My first thought is a while statement, but while's don't yield to the update function. So a while is a no no. I tried yielding at the end of the function if the ending condition wasn't met, but that just postpones the finishing of the function, it does not do so recursively until the condition is met.

So what is the solution? How can I call a function once, pass it time IE: GrabColliders(5), keep the game update going, and have that function repeat until that 5 secs is up. I have the function to grab and process colliders, and how to check the time elapsed etc, but how do I keep the function going, with only 1 call, until the condition is met. I would think it has something to do with calling it recursively? If I try to call the same function from itself however, I get an error?

Any help? And thanks in advance for any advice you can offer! Smile

-Grant

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

Answer by qJake · Jun 19, 2010 at 11:12 AM

IEnumerator DoSomething(float TimeToDie)
{
     float elapsedTime = 0;
     while(elapsedTime < TimeToDie)
     {
          // Perform logic here
elapsedTime += Time.deltaTime; yield return new WaitForEndOfFrame(); } }

Just start that coroutine like you normally would, and don't put any logic in there that "blocks" the statement, i.e. something that is processor-intensive, or takes a long time to complete.

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 Grant 1 · Jun 21, 2010 at 01:56 PM 0
Share

Ok, awesome. I thought that'd be the solution and it is. yield;. Now I have another problem, how do you call yield from within a class/object. The compiler gives me no errors, but when I execute the object function, it locks up when yield is called? Is it a namespace problem or something? Any help is greatly appreciated :D

avatar image qJake · Jun 21, 2010 at 10:12 PM 0
Share

You can only yield from within a coroutine. Don't do it anywhere else. Coroutines have to be started with StartCoroutine(), must have the return type IEnumerator, and must contain one yield return ___;.

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

Invoke repeating OR coroutine with WaitForSeconds? 1 Answer

Yield (frames) VS Time.frameCount? 1 Answer

How do I fix yield not working in while loop? 1 Answer

How can I have a while(www is loading) loop? 1 Answer

Script wait for 3 seconds before running - stops it working altogether 2 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