- Home /
Yielding in a loop only as needed?
I have a couple of loops that are running as coroutines, and everything is working as expected.
I have one concern however; I think because I have a yield at the end of a loop, it is forcing the program to yield every time through.
I suspect this is causing these loops to take longer than expected, since sometimes, it ought to be able to make it through this loop more than once during a frame.
Is there any way to let a loop keep running until it NEEDS to yield?
js or c#? I believe in c# a yield can be conditional, you just have to make sure that all conditional fall throughs are returning at least a null value within your loop structure if no yield needs to take place.
JS, but I can switch over to C if I have to. It'd be a pain, but do-able.
I'm hoping someone will tell me about a magical "Update Needed" flag that will let me know if the loop is O$$anonymous$$ to go again, or if it needs to yield...
Yield always yields a frame. If you don't want it to wait a frame, then don't execute the yield. But it sounds like you're trying to use coroutines as threads, which they aren't. You should probably just use threads ins$$anonymous$$d of trying to force coroutines to do things they aren't meant to do with a lot of convoluted logic.
That would be because I don't know anything about threading...
Look up System.Threading on $$anonymous$$SDN. For a Unity example, see here.
Your answer
Follow this Question
Related Questions
www class blocks script execution 1 Answer
yield on a www never completes 10 Answers
Var change between 2 RPC calls / Coroutine problem 1 Answer
How to start at a specific coroutine? 0 Answers