Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help  Creating rope at runtime looks unprofessional because of coroutines. How to fix?
#3
(06-05-2019, 07:03 PM)josemendez Wrote: No need to wait for coroutines to be done over multiple frames, if you don't want/need asynchronous initialization. Simply advance the coroutine to completion before continuing execution:

Code:
IEnumerator coroutine = gg.GetComponent<ObiRope>().GeneratePhysicRepresentationForMesh();
while (coroutine.MoveNext());

Note that this is not some Obi-specific trickery. It's part of the concept of "coroutine", that you don't seem to understand well. They're not magic async code, nor do they run in a separate thread. They're generally used to distribute lengthy calculations over multiple frames, but you do not *have* to use them like this. Instead of telling Unity to advance the coroutine over several frames (which is what StartCoroutine does), you can run it synchronously by calling MoveNext() until it finishes.

Obi exposes potentially long initialization methods as coroutines, in case you want to show a loading bar, wait for multiple coroutines to be completed, etc. Think of it as "professional courtesy" Guiño. But otherwise, they're regular methods that can be run synchronously just like any other method.

Thanks for the reply!
Ahhhhhh interesting, I tried looking into stopping the asynchronous initialization, but couldn't find much about it. I figured it would be easier to just not use a coroutine, because Im not interested in doing something over the course of multiple frames. 

I'm having a hard time getting this to work still though, and having trouble wrapping my mind around the nested coroutines in this issue. I tried a couple different implementations, and physics would never be added, or it would only create some of the ropes and not assign the variables, or some other issue. 

Sorry, but what exactly am I supposed to do here?
Reply


Messages In This Thread
RE: Creating rope at runtime looks unprofessional because of coroutines. How to fix? - by yyy-2c2p - 06-05-2019, 10:55 PM