Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

Question about nested Colliders

Discussion in 'Physics' started by Kiupe, Nov 30, 2018.

  1. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hello,

    I have a game object which is draggable. The GameObject hierarchy is like this :
    • Root
      • RigidBody2D
      • Collider2D (trigger) which serves to know when the the game object has been clicked on.
      • Sub-GameObject
        • Collider2D which serve to collide with the environnement colliders
    By default the first Collider2D (trigger) is enabled and the second one is disabled.
    When the object is clicked the first Collider2D (trigger) is disabled and the second one is enabled.
    When moving the game object by setting its rigidbody2D position (MovePosition) it seems that collisions from the Collider are not detected or at least not taken into account.

    My question is : Does a rigidbody2D take care of all Collider2D in its hierarchy ?

    Thanks
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,612
    When a collider is added to the hierarchy, it'll search for a Rigidbody(2D) on the same GameObject and attach to that. If not found it'll continue searching up the hierarchy until it finds one and attaches to it. If it doesn't find one then it implicitly connects to the hidden static body that permanently lives in the world-space origin i.e. the collider is then static.

    All Collider(2D) live in the Rigidbody(2D) space so when a body moves, so effectively do the colliders.

    The position of a collider in the hierarchy has nothing to do with its ability to detect collisions but without more info I'm not sure what to suggest. Maybe you're looking for a callback in which case it might be something in your script or maybe you're looking for a collision response in which case it might be the collision layers set-up on the sub-gameobject.

    If you have a simple reproduction project you could share then it'd probably make it easier/quicker to help.
     
    Wilhelm_LAS likes this.
  3. Kiupe

    Kiupe

    Joined:
    Feb 1, 2013
    Posts:
    528
    Hi,

    No, I'm not looking for callback - just for collisions to happen. I made a test and invert colliders in the hierarchy and then collisions are detected. So it seems to me that it has something to do with that but not 100% sure. I'm using LWRP - I don't think it has something to do with that, but maybe I should try without it.

    Thanks
     
  4. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,612
    Are you sure you've not got something odd going on like Transform XY scale of zero on the child causing the collider geometry to be ignored. You'll see this as a warning in the collider component in the inspector though. Rendering has nothing whatsoever to do with physics so it's nothing to do with LWRP.

    Might be good if you could at least post an image of the GameObjects in question and their settings etc in the inspector.