[2D] [C#] Player dying at respawn at checkpoint

Hi

I’m making a 2D platformer game, and I keep running into a fairly simple problem, but for me it’s just hard to find out the cause of it.

Sometimes when the player spawns (either at startup or when respawning at a checkpoint), he gets stuck in some kind of loop that keeps killing him over and over again. This doesn’t happen often, but when it does, it’s obviously quite annoying.

Below you will find the code I’ve used for the checkpoints, and the coroutine I used to respawn the player. The thing is, I know they work, because most of the time nothing’s wrong, so it has to be some kind of tiny mistake I never noticed.

Also, this might just be a coincidence, but I feel like this issue happens more often the longer I play a session. Again, this might be completely wrong.


Checkpoints

public class Checkpoint : MonoBehaviour 
{
    public LevelManager levelManager;

    void Start()
    {
        levelManager = FindObjectOfType<LevelManager>();
    }

    void OnTriggerEnter2D(Collider2D other)
    {
        if (other.name == "player")
        {
            levelManager.currentCheckpoint = gameObject;
            Debug.Log("Activated checkpoint at" + transform.position);
        }
    }

Respawning

public void RespawnPlayer()
	{
		StartCoroutine("RespawnPlayerCo");
	}

	public void KillCo()
	{
		Debug.Log("Player died.");
		Instantiate(deathParticles, player.transform.position, player.transform.rotation);
		player.enabled = false;
		camera.isFollowing = false;
		renderer.enabled = false;
		ScoreManager.AddPoints(-pointPenaltyOnDeath);
	}

	public void RespawnCo()
	{
		Debug.Log("Player respawned.");
		player.knockBackCount = 0;
		Instantiate(respawnParticles, currentCheckpoint.transform.position, currentCheckpoint.transform.rotation);
		player.enabled = true;
		camera.isFollowing = true;
		renderer.enabled = true;
		healthManager.FullHealth();
		healthManager.isDead = false;
		player.transform.position = currentCheckpointPosition;     
	}

    public IEnumerator RespawnPlayerCo()
    {
		KillCo ();
        yield return new WaitForSeconds(respawnDelay);
		RespawnCo ();
    }

Does anyone have an idea what might be going wrong here? Just in case it’s necessary, here’s a screenshot of how I have my checkpoints set up in the scene:

alt text

Figured it out, I had a few statements in the wrong order.
I should’ve changed the player’s position before actually re-enabling him, while this used to happen after all the other things.