Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Coroutines in ComponentSystems

Discussion in 'Entity Component System' started by emreCanbazoglu, Mar 25, 2018.

  1. emreCanbazoglu

    emreCanbazoglu

    Joined:
    Jan 31, 2012
    Posts:
    15
    Coroutines were a huge part of the classic Unity Entity-Component architecture. Is there a way to use (or does it make sense to use) Coroutines in ECS? Or what kind of approach should we follow while defining a sequence of actions or waiting for some other action to happen?

    Thanks.
     
  2. 5argon

    5argon

    Joined:
    Jun 10, 2013
    Posts:
    1,554
    The sequence of action right now would be execution order for ComponentSystem and job dependency for JobComponentSystem. Coroutine's unit of action was a method/delegate and now we think in System instead.

    If a logic of one system needs to wait multiple frames for something to happen first (as yielding a coroutine did) now I think in terms of system activation criteria. When matching entity appears it continue running and that is the result from other system.
     
  3. Necromantic

    Necromantic

    Joined:
    Feb 11, 2013
    Posts:
    116
    I never saw Coroutines as such a big thing and I don't think they were ever made to be thread-safe.
    I think maybe with the Reactive Systems you may be able to do some Coroutine like behaviours. For example add a "WaitForSeconds" component that has a time on it, when it expires it gets removed and on removal the Reactive System is triggered to do whatever.
    A lot of the convenience of Monobehaviours will be missing for a while with the ECS.
     
    zulfajuniadi likes this.