playMaker

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

mindlube

  • Playmaker Newbie
  • *
  • Posts: 32
    • View Profile
Start Coroutine and wait (i.e yield return StartCoroutine) ?
« on: August 31, 2011, 10:17:42 AM »
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, 11:55:30 AM by mindlube »

mindlube

  • Playmaker Newbie
  • *
  • Posts: 32
    • View Profile
Re: Start Coroutine and wait (i.e yield return StartCoroutine) ?
« Reply #1 on: August 31, 2011, 10:35:50 AM »
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
    • View Profile
Re: Start Coroutine and wait (i.e yield return StartCoroutine) ?
« Reply #2 on: August 31, 2011, 10:36:38 AM »
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
    • View Profile
Re: Start Coroutine and wait (i.e yield return StartCoroutine) ?
« Reply #3 on: August 31, 2011, 11:01:33 AM »
@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
    • View Profile
Re: Start Coroutine and wait (i.e yield return StartCoroutine) ?
« Reply #4 on: August 31, 2011, 11:22:00 AM »
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
    • View Profile
Re: Start Coroutine and wait (i.e yield return StartCoroutine) ?
« Reply #5 on: August 31, 2011, 11:48:38 AM »
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!