I try to be straightforward in my titles… it’s exactly what it sounds like.
I simply call a single Coroutine, which does not call any other coroutines, at any time… I call this single coroutine via the “StartCoroutine(Coroutine())” method at the Start() method… (this also occurs when I call it from Awake or anywhere really.)
Shouldn’t it only be getting called once???
Nevertheless, I am getting MAJOR Lag Spikes from GC Alloc according to the profiler, from this coroutine being repeatedly called… this issue persists in numerous scripts I’ve written. I’m completely confused rn; I’m about ready to never use Coroutines again…
Also, I am NOT calling it from ANYWHERE else, even though it says it’s getting called from the Update method, I have triple and quadruple checked with our 'ol friend Ctrl+F… it’s ONLY in Start().
Any input is appreciated.
UPDATE:
So I’ve FINALLY found out what is causing it to continue calling the Coroutine… though it doesn’t make sense… here’s my test:
private IEnumerator Test()
{
while (brainStarted != BrainStarted.True)
{
debugLog = "WAITNG....";
yield return null;
}
debugLog += " - EXITED";
}
and of course it DOES meet the exit condition after a short time… and surely enough, I DO get the " - EXITED" logged. (debuglog is just a reference to a static UI text Component) although the conditions are met, it continues to call the Coroutine… I’m continuing investigation - still input is welcome from anyone.
The issue is pertaining to while loops inside of Coroutines… this is very strange.
UPDATE:
So only a minor update, but I also noticed this:
And again, this coroutine (Test()) is merely called one time in the Monobehaviour.Start() method. Via StartCoroutine(Test());
I changed the exit condition from my enum to a bool to verify the issue is not related to the enum… the issue persists.
UPDATE:
Here’s an isolated Class I’ve built for proper testing (still occurring):
using BrainConnect;
using System.Collections;
using UnityEngine;
public class Test : MonoBehaviour {
private bool brainReady = false;
void Start ()
{
ConnectBrain.BrainReady += BrainReadyEvent;
StartCoroutine(TestEnumerator());
}
private void BrainReadyEvent(object s, System.EventArgs e)
{
brainReady = true;
}
private IEnumerator TestEnumerator()
{
while (!brainReady)
{
ConnectBrain.debugLog = "WATING....";
yield return null;
}
ConnectBrain.debugLog += " - EXITED";
}
}
This new isolated script is simply attached to a new Empty GameObject Parented under nothing.
I get the same results.








