Search Unity

OnCollision2D stopped working

Discussion in '2D' started by dorpeleg, Apr 23, 2014.

  1. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Hello community,

    I've asked this question in unity answers and got no replay yet (link), so I decide To try here.

    I have a weird issue with OnCollision2D.
    I've setup my player with a 2D collider, I've also setup the ground he is walking on with a 2D collider.
    The player also has a 2D rigidbody on it, the ground does not.
    The player script (attached to the player) has 2 OnCollision2D methods, OnCollisionStay2D and OnCollisionExit2D.
    The player also has an animator that animates its sprite.
    At that point, everything is working fine, both OnCollision2D methods are being called.
    Then, I added another animation to the character.
    In that animation, I'm also animating the colliders (changing their shape and size).
    As soon as I added this new animation, both of the OnCollision2D methods stopped working, even before I'm calling the new animation.
    If I disable the Animator component on the player, then the methods are working again.

    Any ideas?
     
  2. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
    Hmm, I animate colliders all the time without issue. Are you applying root motion? Are you rotating child colliders with a negative scale?
     
  3. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    I'm not applying root motion and I'm not rotating anything, just changing center and scale of a collider.

    I'm not even sure if animating the collider is the issue, I just now this accord approx the same time I added it.

    The weird thing is, The methods just don't work, even if I haven't played the animation yet.
     
  4. twoski

    twoski

    Joined:
    Mar 27, 2014
    Posts:
    27
    this seems like a common issue, i noticed collision hooks stopped working properly when i added animations to my entity.
     
  5. Pyrian

    Pyrian

    Joined:
    Mar 27, 2014
    Posts:
    301
    Did you set the Rigidbody2D to kinematic? It seems that colliders don't work unless at least one of them is associated with a Rigidbody2D that is NOT kinematic.
     
  6. dorpeleg

    dorpeleg

    Joined:
    Aug 20, 2011
    Posts:
    250
    Non of the rigidbodys is kinematic.
    The collsion is working fine, the colliders are colliding each other, its just the methods that don't run.