Unity5.6 Collision2D contact points array problem
When I updated my Unity version 5.5 to 5.6, an error occured about the Collision2D.contacts array. When I try to access the contacts array, I can not get contact point info now.
void OnCollisionExit2D(Collision2D col)
{
if (col.gameObject.CompareTag("Ground"))
{
if ((_transform.position.y - col.contacts[0].point.y) > colliderHeight / 2 + .15f)
{
Debug.Log ("Contact count = " + col.contacts.Length);
_onGround = false;
ParticleController.PlayDustEffect ();
}
}
}
IndexOutOfRangeException: Array index is out of range. Player.OnCollisionExit2D (UnityEngine.Collision2D col) (at Assets/Scripts/CharacterController/Player.cs:759)
How can I fix the error?
Thanks for your time.
Having same exact problem. Looks like they've changed A LOT about how colliders are working in 5.6. Retrieving contacts with GetContacts() doesn't work too.
Answer by hexagonius · Apr 04, 2017 at 08:24 PM
you won't get contacts on exit. I ran into the same problem. I even received answer from unity support. I don't know if this ever worked, but it didn't with unity 5.5. thinking of it, it doesn't make sense to work too. to detect if two colliders no longer overlap, they just don't anymore. it would be a backtrack for contacts, like inverse continuous dynamic collision detection.
It was definitely working for me in 5.5. And it totally makes sense to detect which colliders triggered on exit event and where the exit happened.