I have about a hundred CoRoutines calls all over my program. Now i find im in a situation where i have to stop some of them before they naturally end, by using StopCoroutine.
The problem is how to do it, i know when CoRoutine starts it returns an object of that coroutine that you can use to stop it like this
I want to store each running coroutine object in a list, so i can stop it at anytime by accessing the list, if the coroutine ends before i call stop coroutine, remove that coroutine from the list automatically so that i dont try to stop one that is already ended.
IEnumerator myFunc(…) // the last line of the coroutine would delete itself from the list
{
…
CList.remove(???); <----- how do do this
}
My questions are:
How can i have the co routine remove itself from the list from inside the co-routine? Is there something like a “this” to identify the coroutine? CList.remove(this)???
Yes I probably use too many coroutines. Maybe because I didn’t know enough about unity when I started the project. But its too late now.
All they are doing is animation lerping like slowly opening or closing a window by scaling the transforms local scale plus some other things, but they are too many of them now like 115.
But it seems once I get the coroutines object I can add that to a list. Then I can use that list to stop any coroutines. The problem is how to know when each coroutines has ended in order to remove it from the list.
I thought to remove itself from the list inside the coroutines as the last thing bit there seems to be no way to know the I’d of the coroutines object while inside the coroutines in order to remove itself from the list. There need to be something like a “this” pointer for the co routine which points to the coroutine object itself that can be accessed from inside the co routine, but there is no such thing it seems.