Layers and Tags

The free version of MEC only has tags, but MEC Pro adds layers. Collectively tags and layers are called graffiti because they are both just ways to identify a particular instance of a coroutine. The only real difference between a layer and a tag is that a layer is an integer and a tag is a string, but in MEC Pro you have the option of supplying one, the other, or both. Once you supply graffiti for an instance, you can pause/resume, kill, or use that graffiti for RunCoroutineSingleton.

In Unity every GameObject is assigned a unique number, which can be accessed by calling gameObject.GetInstanceID(). The instance id can change every time you run the application, but it is guaranteed that no other gameObject instance will be assigned the same id during a single run. So even if you have a swarm of enemies that all have the same scripts attached to them you can still run them on a layer which is the instance id of the gameObject they were created on and then kill all coroutines attached to one particular enemy using

Timing.KillCoroutines(enemy.gameObject.GetInstanceID());

 
If you had, say, an amnesia gun you could graffiti all your enemy’s AI logic with both the instance id and a tag:

Timing.RunCoroutine(_EnemyAI(), gameObject.GetInstanceID(), "AI");

// Somewhere else in code:
void HitEnemyWithAmnesiaGun(EnemyController enemy)
{
    Timing.KillCoroutines(enemy.gameObject.GetInstanceID(), "AI");
}

 
KillCoroutines only kills the instance that match all the graffiti that you pass in, so if you coded it right then the above code would make the enemy stand there and do nothing until you killed it, but would also leave any other coroutines that might be running on that particular character untouched.

Unity’s coroutines will always cancel all of the coroutines that are associated with a GameObject whenever you disable that object. MEC coroutines don’t have this behavior by default (but you can add it using CancelWith). Sometimes you would rather just pause a coroutine while it’s disabled and then resume it as soon as the object is reenabled. That sort of pattern is really easy to set up in MEC like this:

void Start ()
{
    Timing.RunCoroutine(_MoveUpAndDown(), gameObject.GetInstanceID());
}

void OnEnable()
{
    Timing.ResumeCoroutines(gameObject.GetInstanceID());
}

void OnDisable()
{
    Timing.PauseCoroutines(gameObject.GetInstanceID());
}