- Home /
lists, iterate and coroutines
Quick question: if I pass a list to a method that iterates over a list as a parameter, but change the list while the iteration is running, will an error be thrown?
Example:
IEnumerator DoSomething(){
while(true){
DoSomethingElse(list)
yield return new WaitForSeconds(2);
}
}
DoSomethingElse(List<type> list){
foreach(Type t in list){
t.SomethingToDo();
}
}
Do I even need to pass the list? The idea behind this is to be able to change the list at anytime while the coroutine is running.
Comment
Answer by hexagonius · May 07, 2018 at 06:29 AM
you're not dealing with multithreading here, nothing will access the list in parallel. coroutines are not threaded.