Coroutine not working but only sometimes?

Hello guys! There’s this problem I have where I have a quite simple code which after a button has been clicked, the event system runs a public function Build ().
It’s worth mentioning that “prefabConst” is a under construction sprite, and “prefab” is the finished building sprite. So everything works flawlessly until the Construction coroutine. Sometimes and for no apparent reason (and I repeat, ONLY sometimes) it doesn’t run. I’m not sure if it doesn’t run but the construction sprite persists which only tells me it didn’t run in the first place.

I failed to find any patterns in why it decides not to work (like clicking too fast).

Does anybody have an idea on how could I approach this issue?

     public void Build () {
         x = Random.Range (-4.5f, 4.5f);
         y = Random.Range (-2.5f, 2.5f);
         z = 0;
         pos = new Vector3 (x, y, z);
         GameObject storeMe = Instantiate (prefabConst, pos, Quaternion.identity);
         StartCoroutine (Construction(storeMe));
}
     IEnumerator Construction (GameObject destroyMe) {
         yield return new WaitForSeconds (5);
         Instantiate (prefab, destroyMe.transform.position, Quaternion.identity);
         Destroy (destroyMe);
     }

Coroutines are attached to whatever component calls StartCoroutine. So if the GameObject that you’re calling Build() from is destroyed then the Coroutine is automatically stopped. Maybe you’re calling Build() from a button or something that’s getting deleted, or you’re changing scenes before the coroutine is done?

I don’t think so, the script is attached to a button in the GUI which is never destroyed. Also I have only one scene in the game.

Putting in a few Debug statements may help with judging code flow. I can’t see any obvious cause.

I added debug statements and to my surprise I can not reproduce this error when a debug.log is running in the script. It’s incredible. Does this even has an explanation?

EDIT: Nevermind, after alt + tabbing unity it broke the code. But I believe it was just some probability thing. I refuse to believe alt + tabbing unity breaks the code.