Possible Unity BUG? Or am i missing something

Hey guys i recently ran into a problem and kinda stumped on why it acted this way. What happened was i have a gameobject with a box collider attached to it. In this gameobject i have a function to respawn the gameobject when it is killed which simply hides its render and moves it back to its starting position. Now the problem with it was that just hiding the renderer the gameobjects collider would still block incoming projectiles so i added to the respawn code to make the collider.active = false. Now when i did this my respawn code stopped performing its yield statement. Here is the code for reference in C#:


    float respawnTime = 5f; // How long to wait before respawning</p>

<pre>`void Start()

{ StartCoroutine(RespawnGameObject()); }

// Function to Respawn the GameObject
private IEnumerator RespawnGameObject()
{
    gameObject.collider.active = false; // Deactivate the gameObjects collider
    gameObject.renderer.enabled = false; // Hide the gameObjects 

    Debug.Log("Before the Yield");
    yield return new WaitForSeconds(respawnTime);
    Debug.Log("After the Yield");

    gameObject.collider.active = true; // Reactivate the gameObjects collider
    gameObject.renderer.enabled = true; // Make the gameObjects visible again
}

`

The above code is what i believe is possibly a bug or am i missing something? The debug statement "Before the Yield" is returned but not the "After the Yield". However with the code below both are returned:

```

float respawnTime = 5f; // How long to wait before respawning</p>
`void Start()

```

{ StartCoroutine(RespawnGameObject()); }

``` // Function to Respawn the GameObject private IEnumerator RespawnGameObject() { gameObject.collider.isTrigger= false; // CHANGED TO A TRIGGER gameObject.renderer.enabled = false; // Hide the gameObjects Debug.Log("Before the Yield"); yield return new WaitForSeconds(respawnTime); Debug.Log("After the Yield"); gameObject.collider.isTrigger= true; // CHANGED TO A TRIGGER gameObject.renderer.enabled = true; // Make the gameObjects visible again } ```

`

Now is this a bug or again am i missing something? I dont understand why disabling a collider would effect a yield statement. I have recreated the problem in a seperate project where i add this script to a cube and no other scripts are active and the trigger version works but the active does not. If anyone knows why this is please let me know! Thanks again

You're setting the GameObject inactive, not the collider (Component.active is a shortcut for setting the GameObject active status).

Since the GameObject is inactive, Unity doesn't call back into the coroutine

It should actually be causing a compilation warning about it being obsolete, along the lines of: the active property is deprecated on components. Please use gameObject.active instead. If you meant to enable / disable a single component use enabled instead.

though that isn't so useful for colliders, which don't have an enabled property