Problems with Coroutines

I’m making a platformer and my setup goes like this in the first picture you will see the player, a ground piece, and the camera with a killzone childed to it.


when the player falls it triggers the Coroutine RespawnCo however I get this error

For your convience here is the code in question. The only other script that has anything to do with respawning is the Player script, which calls the Respawn function

using System.Collections;
using UnityEngine;

public class LevelManager : MonoBehaviour
{
    [SerializeField] float waitToRespawn = 2f;

    Player player;
    ResetOnRespawn[] objectsToReset;

    void Start()
    {
        player = GetComponent<Player>();
        objectsToReset = FindObjectsOfType<ResetOnRespawn>();
    }

    public void Respawn()
    {
        StartCoroutine("RespawnCo");
    }

    public IEnumerator RespawnCo()
    {
        player.gameObject.SetActive(false);
        yield return new WaitForSeconds(waitToRespawn);
        player.transform.position = player.respawnPos;
        player.gameObject.SetActive(true);
    }
}

Are you sure you can call player.transform.position = player.respawnPos; on an incative object?

Yes, that is a Vector2 on the player script that gets set on Start to the player’s position.

This code seems to be implying that the LevelManager is attached to the player object. Is that right? If so, you are disabling the very object that is running this coroutine - a big no-no. Your LevelManager script should be attached to a different GameObject hierarchy entirely or you should find a different way of ‘disabling’ the player object (like disabling input and rendering components only).

Oh gosh, I just realized that I did GetComponent instead of FindObjectOfType. it works now.