StartCoroutine not starting coroutine

For my graduation project I'm looking into building a virtual twin platform using Unity, everything works perfectly except for one thing: My timer coroutine does not get started AT ALL.

It prints debug logs up until the point where the coroutine should be starting but once it should enter the function it stops printing. I am using the exact same script in another project, but it works perfectly in there (this makes me believe that there is nothing wrong with my IEnumerator)

I already checked for the following possible causes:

  • Destruction of any related object, this should not happen at any time since my gameobjects don’t have to be destroyed at any point during runtime.

  • Random call of StopCoroutine or StopAllCoroutines, this does not happen anywhere (only in a button of which I removed the onClick action to be sure it was not causing this bug)

  • My gameobjects dont get disabled or set inactive antwhere

  • None of the fields needed for this function are unassigned or NULL

  • The Timescale is set to 1 in the project settings and does not get changed anywhere.

I also tried switching out the coroutine with an Invoke function, this gave the same result.

I have been working with Unity (and its coroutines) for a couple of years now, but have never encountered this problem.
Does anyone have tips on where to look further for the cause of this problem?

 public void StartTimer()
    {
        Debug.Log("timer has been started by the timerscript");
        this.StartCoroutine(this.Timer());
    }

    public IEnumerator Timer()
    {
        Debug.Log("entered timer ienumerator");
        yield return new WaitForSecondsRealtime(timeToTrigger);
        Debug.Log("timer ran out, sending timeout");
        sendTimeout();
    }

My code runs up until the “timer has been started by the timerscript” message but the coroutine never gets started.

I really would appreciate all the help people can give me to find this final bug in my code, so i can finally graduate.

Hi, i’ve checked your code and it is working fine, may be you are missing some liberary like “System.Collections”, here is your code i compiled it and it is working fine:
using System.Collections;
using UnityEngine;

public class forumtest : MonoBehaviour
{
    // Start is called before the first frame update
    void Start()
    {
        StartTimer();
    }

    // Update is called once per frame
    public void StartTimer()
    {
        Debug.Log("timer has been started by the timerscript");
        this.StartCoroutine(this.Timer());
    }
    public IEnumerator Timer()
    {
        Debug.Log("entered timer ienumerator");
        yield return new WaitForSecondsRealtime(2);
        Debug.Log("timer ran out, sending timeout");
        //sendTimeout();
    }
}