playMaker

Author Topic: Start Coroutine and wait (i.e yield return StartCoroutine) ?  (Read 11069 times)

mindlube

  • Playmaker Newbie
  • *
  • Posts: 32
Start Coroutine and wait (i.e yield return StartCoroutine) ?
« on: August 31, 2011, 01:17:42 PM »
surprised there is a Start Coroutine but not a start + wait for coroutine.

edit: actually never mind!  It's BETTER to use Start Coroutine action, then just call a custom event transition at the end of a coroutine :)
« Last Edit: August 31, 2011, 02:55:30 PM by mindlube »

mindlube

  • Playmaker Newbie
  • *
  • Posts: 32
Re: Start Coroutine and wait (i.e yield return StartCoroutine) ?
« Reply #1 on: August 31, 2011, 01:35:50 PM »
Hmm, this is not as trivial as I thought to create my own Action. Please make OnEnter to be polymorphic to have IEnumerator return type. Much like Unity's Start and Awake methods may be void return or they may by coroutines (IEnumerator return type). That would add a great deal of flexibility about what kind of Actions can be created! (coming at this from a programmer's perpective)

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: Start Coroutine and wait (i.e yield return StartCoroutine) ?
« Reply #2 on: August 31, 2011, 01:36:38 PM »
Would you be interested in telling me what a Coroutine is for? I see them mentioned everywhere but i dont know what you use it for or really what it is..

If not thats ok too.  :)

I assume it is like subroutine you want to jump to and wait for it to return with values maybe?

Q

mindlube

  • Playmaker Newbie
  • *
  • Posts: 32
Re: Start Coroutine and wait (i.e yield return StartCoroutine) ?
« Reply #3 on: August 31, 2011, 02:01:33 PM »
@qholmes, in C# there is the keyword "yield". Unity's implementation of coroutines is pretty nice. They are commonly used in Unity to create game logic, even simple FSMs, in scripts with C# or Unity script. It's tremendously useful. Indispensable even. Start here
http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html

qholmes

  • 1.2 Beta
  • Hero Member
  • *
  • Posts: 509
Re: Start Coroutine and wait (i.e yield return StartCoroutine) ?
« Reply #4 on: August 31, 2011, 02:22:00 PM »
Hey thanks!!!!

I dont get what an IEnumerator is.. but i read quite a bit there and it made sense for the most part.. I have thought about this type of logic but did not know what it was called.. leaving one FSM and being able to return to the same spot upon return... I can see this being very beneficial.

Q

mindlube

  • Playmaker Newbie
  • *
  • Posts: 32
Re: Start Coroutine and wait (i.e yield return StartCoroutine) ?
« Reply #5 on: August 31, 2011, 02:48:38 PM »
Actually, now that I dig into this a little more, when using the Start Coroutine action,  it's only a single line of code to put at the end of my coroutine:

cachedFSM.ChangeState("proceed");

In fact this is so simple that there really is no need for a Start Coroutine and wait! Yay for extensible event transitions!