Hi!
The following package demonstrates my problem.
TestOnCollisionEnter.unitypackage
Whenever I include OnEnable() in my script, I’m unable to respond to collision events.
I also expect to be receive collision events, while using WaitForSeconds().
The scene looks like this:
- Two boxes collide almost immediately after the scene starts.
- One of the boxes is falling by gravity, the other is kinetic.
- Both boxes have a collider and a rigidbody.
- One of the boxes have the following script.
import UnityEngine import System.Collections class BusyCollider (MonoBehaviour): // def waitAndSee() as IEnumerator: // Debug.Log("waiting...") // yield WaitForSeconds(2.0f) // Debug.Log("done!") // // def OnEnable(): // StartCoroutine(waitAndSee()) // def OnEnable(): // pass def OnCollisionEnter (other as Collision): Debug.Log("CollisionEnter")
My results:
- Case 1: using the code as it is, OnCollisionEnter() gets called.
- Case 2: if OnEnable() exists, OnCollisionEnter() does not get called.
- Case 3: if OnEnable() starts a coroutine that waits while the boxes collide, the result is the same as in Case 2.
Why does not OnCollisionEnter() get called? Can I also expect OnCollisionEnter() to be called in Case 3?
Any help is appreciated.