0
Planned

Yield Return in Coroutines

gyltefors 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 9 1 duplicate

It seems like coroutines are supported, but I could find a Yield Return node. Without it, there is not much you can do with coroutines. Also, is there other support for aync operations, apart from using FSMs?

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):

Duplicates 1

Another related question is: if a custom unit (function) return a Coroutine, will FlowMachine wait this coroutine to finish? Or just treat it as a normal function (return immediately and execute the next unit)?

Edward.

They will execute then continue immediately just like calling StartCoroutine outside of a routine. It will run it in the background async, not directly wait in the graph unit. I've got Coroutine in Macros section, but maybe instead of trying to add it's own yielding for that, I can look into what's possible with that return type you suggested. I'll do some testing today. Anything we can do to bring more functionality that doesn't need done in script. 

Thanks, let me give you an additional example to description the scenario to use this unit.

Let's say I have a class Hero, it has three methods: MoveTo(position), LightAttack(), HeavyAttack(), each of these method is implemented with Coroutine.

class Hero
{
   public Coroutine MoveTo(Position)
   {
      return StartCoroutine(IE_MoveTo(Position));
   }
   
   public Coroutine LightAttack()
   {
      return StartCoroutine(IE_LightAttack());
   }
   
   public Coroutine HeavyAttack();
   {
      return StartCoroutine(IE_HeavyAttack());
   }

   ...
}

If I try to implement a special attack with script (which is a combination from the above methods),  following is the code:

public Coroutine SpecialAtttack();
{
   return StartCoroutine(IE_SpecialAttack());
}

IEnumerator IE_SpecialAttack()
{
  yield return LightAttack();
  yield return LightAttack();
  yield return LightAttack();
  yield return MoveTo(new Vector2(1, 0));
  yield return HeavyAttack();
}


So, if I could replace this piece of code with Bolt visual script, it will be very good! Since the special attack is quite different from hero to hero.

Couldn't fit all parts in here so i just did less sequences, no real logic, screen space and all. Essentially with the Coroutine Macros, you could handle it something like this. 






The alternative would be to use state machines and logic in each state to determine which to transition. or even smarter, something in the above graph that manages firing events to change transitions.

Thanks a lot for your detailed explanation.

Since there is no straightforward way to implement my requirements with bolt, I will keep on using coroutine.

Edward.

+1
Answered

Hi Gyltefors!

You won't find units named "yield return", but look for "Wait" and you'll find all of Unity's default yield instructions.

I'm planning on adding an additional custom yield return unit in the future for edge cases and nested coroutines.

You can use async operations (as in: wait until, etc.) in Flow Machines too, not just State Machines.

My main use case is to wait for things like asset loading, where I use nested coroutines now. With the current version of Bolt, I guess using states like Loading in a state machine is the best workaround.

Planned

I agree! Just switching this to an Idea thread to make sure I remember implementing it!