Search Unity

Why is rigidbody2D calling OnCollisionEnter2D method?

Discussion in '2D' started by scnoobi, Jan 9, 2015.

  1. scnoobi

    scnoobi

    Joined:
    Feb 26, 2013
    Posts:
    25
    I got 1 gameobject with 1 child under it.

    child components:
    script with OnCollisionEnter2D(Debug.Log("child"));
    circleCollider2D

    for parent
    boxCollider2D
    rigidbody2D
    script with OnCollisionEnter2D(Debug.Log("parent"));


    Debug Log with all of the above:
    parent
    child
    parent
    child
    etc.

    If i remove parent rigidbody2d:
    child
    child
    child
    etc

    if i remove parent boxCollider2D:
    parent
    child
    parent
    child
    etc

    Why is it not just the collider calling OnCollisionEnter2D? This seems like the most logical thing that should happen


    I noticed if you do the same test but for normal rigidbody and a collider only the rigidbody calls the OnCollisionEnter method Where as if it doesn't have a rigidbody the collider will call it(not both like in the OnCollisionEnter2D case.)
    if you do the same experiment with 3d colliders and rigidbodies then if you have a rigidbody ONLY that will call OnCollisionEnter on this gameobject where as if you remove the rigidbody the OnCollisionEnter will happen on the child

    Hopefully this is a bug because it is silly that OnCollisionEnter2D and OnCollisionEnter should be called by the rigidbodies (Should be called by the colliders.)

    Is this a bug or intended(the 2d part is what i am most interested in).
     
  2. Mike-Geig

    Mike-Geig

    Unity Technologies

    Joined:
    Aug 16, 2013
    Posts:
    254
    Can you post screenshots of the actual game objects and your code? Also, what are you colliding them against?