• 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 superventure · Jun 02, 2011 at 04:11 PM · functionyieldsecondscorrupt

Weirdness.. Why does putting yield in function corrupt commands?

Hello. I have a couple of functions set up with a yield to wait for seconds in each. After the yield, I have some other instructions of course but, for some reason the 2nd set of instructions will not execute- or in the other function it will completely not execute.

When I take the yield out of the functions, they work perfectly?

The first function is started via InvokeRepeating. With yield, it will completely not work. The yield is no way longer then its repeat rate.

The second is in an Update function and is called on a GetButton Down command. With yield, it does execute, but I also have a

 for(var foos in fooObjects){ 
 foos.GetComponent.ladida
 }

code in it as well, this part will not work with yield in the function.

Why do they malfunction with yields? I do need to have yield in them.

please help, and thank you.

Comment
Add comment · Show 2
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 Ray-Pendergraph · Jun 02, 2011 at 04:22 PM 0
Share

Can you post more code please. There is not enough here to really answer your question without really guessing.

avatar image superventure · Jun 02, 2011 at 04:44 PM 0
Share

NOTE - I figured out the problem with the GetButton function

As for the invokerepeating, there is definitely an issue there. The script is exactly how it sounds

function Start(){

InvokeRepeating("foo",5,10);

}

function foo(){

print ("did foo happen?"); yeild WaitForSeconds(2); print ("foo did happen");

}

without yield, it will execute and repeat perfectly. With yield, it wont even print "did foo happen"

1 Reply

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

Answer by Ray-Pendergraph · Jun 02, 2011 at 06:07 PM

I have never used InvokeRepeating but according to the documentation there is no indication that the thing that is repeating should be a coroutine. In fact this behavior is consistent with a coroutine method being called directly and not being called as a coroutine. All the code up to the first yield will operate and nothing else will ever happen. That sounds like what you have described.

This is because all of the code up to the first yield is in the first 'case' of the coroutine which gets called right after the creation of the Enumerator for the coroutine. If you want a repeating coroutine that can yield just use a for loop from 1 .. 5 or something, yielding in between.

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

StartCoroutine important for using yield? 1 Answer

How to use yield within a class function 2 Answers

Can a function maintain its argumanet data after it is run? 2 Answers

How can I use a yeild during an udate? 1 Answer

Yield Causing function not to be called on multitouch script 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