Arbitrary line in one method prevents another for working?

This is blowing my mind…

I have a loop.

IEnumerator Start()
     while(true) {
          if(collectedFloatList.Count > 0){
               OverallLatencyReport(collectedFloatList.Avarage); // < Call Method 1;
               CheckForEvent (collectedFloatList);   // Call Method 2; 
      yield return new WaitForSeconds(1f);

The problem is, this works perfectly fine if I comment out Method 2, “CheckForEvent” but with the method in there, it will not execute method 1 “OverallLatencyReport”. So I started commenting out some lines, in Method 2 and found the line that makes method 1 stop working but that line has nothing to do with Method 1. What is worse is that if I swap the “guilty” line with another line that also has nothing to do with Method 1, and comment out the guilty line, the new random line becomes the “guilty” line and stops method one for working.

I do not understand what I am missing.

Here is Method 1 and 2.

void OverallLatencyReport(float lag) // This method does not do the job when "guilty" line is active
     GameObject lagBarClone = Instantiate (latencyHitPrefab) as GameObject;
     lagBarClone.GetComponent<Slider>().value = lag;
     if(activeGraphHits.Count > maxGraphHit)
     overallLatencyInfo.text = (lag).ToString() + " ms";

And this is the method with the “guilty” line?

void CheckForEvent(List<float> ALPS)
     float minLatency = ALPS.Min();
     float.maxLatency = ALPS.Max();
     bool spike = (minLatency *2 < maxLatency);
     bool drop = (maxLatency / 2 > minLatency);
          GameObject textClone = Instantiate (eventTextPrefab) as GameObject) as GameObject;
          Text newEvent = textClone.GetComponent<Text>();
          newEvent.transform.SetParent(eventParent); // This is the guilty line if not commented out

          // BUT!!! if I comment it out, and I uncomment the next line like so. 
          // newEvent.transform.SetParent(eventParent); 
          newEvent.text = "Spike at " + (Time.time -autoToggleTime).ToString(); // Now this is the guilty line and stops the first method for performing. 

No error, just stops working. Any ideas?

Are you getting any errors in the console?

My guess is that as both “guilty” lines are using ‘newEvent’, the problem is that newEvent is null, which causes an exception and halt the coroutine (assuming Start is a coroutine. If so you might want to rename for clarity).

If the above is correct, you need to look at how newEvent is set and that your GetConponent call is successful (will fail if the Text component can’t be found).