Search Unity

OnTriggerStay not detecting compound colliders?

Discussion in 'Scripting' started by ChrisSch, Apr 27, 2016.

  1. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    I'll just copy my question here, since it left the first page and wont ever be answered there. :p

    I have an empty gameobject with a rigidbody, and a tag, and it has a child gameobject (or more) with a box collider.

    I have another gameobject with the OnTriggerStay script, who's suppose to find the tagged object, but its detecting the cube only, of the first gameobject, not the first object's parent with the rigidbody. In other words the compound colliders aren't working. When I don't have the tag check, Its detecting the collider objects themselves instead of the parent with rigidbody.

    Does compound apply only to colliders, and the triggers are too dumb to tell if a gameobject is made of compound colliders, or is something wrong with my Unity version? If its the prior, I should instead search by tag recursively, right? Starting from child going up till it hits the tag.

    I'm using v5.0.1 because I'm making this for an asset, but I also tested it in 5.4 beta, and its the same.

    To sumarize hierarchy:

    1.RigidbodyGO (with tag)
    1a. =>ChildColliderGO

    2.OnTriggerStayGO (trying to detect the tagged GO, but only picks up the child with the collider if I remove the if(other.collider.gameobject.tag == "whatever") conditional, and with the conditional it never detects the parent, same goes for OnTriggerEnter)
     
  2. Zaflis

    Zaflis

    Joined:
    May 26, 2014
    Posts:
    438
    If it's even possible to collide with child object, you haven't set the collision layers from Physics settings. You can set so that objects on 1 layer cannot collide with themselves.

    But still it maybe should be working without layers too. (I mean there is a case where there are multiple enemies each with compound colliders and each enemy as a whole collides with other enemies, this stuff does work.) Make sure that the collision script is not in the child objects, but with the rigidbody.

    And debug name of every object hit that it makes. Ignore collisions with self if it does that.
     
    Last edited: Apr 28, 2016
  3. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    All the collision layers are enabled. But I'm talking about triggers here, there's no collisions happening. I'm checked and double checked and million checked that the script is in place. Kind of have been losing my mind over it for days. lol

    I ended up doing an upwards recursive search in OnTriggerStay to find the parent with tag and rigidbody, since triggers don't seem to detect it.
     
  4. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    Here's a simplified scene. This is basically what I'm trying to do. Its a compound collider setup on the player, and the trigger is suppose to detect the player because it has the rigidbody, but instead it detects the child that has the collider.

    EDIT: fixed the example scene
     

    Attached Files:

    Last edited: Apr 28, 2016
  5. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Triggers don't *have* to have a rigidbody. The documentation says that the message is sent to the RB or the collider if no RB is present so it sounds like it's not bubbling up to parent RBs like regular collisions do.

    Probably intended behavior that could be documented better.
     
  6. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    Could you link me to that documentation? I've looked at the colliders manual but haven't found anything involving my example scene. I found bug reports with OnTriggerStay not working, but I'm not sure if they're related to my case, and they're fixed in later versions, but its the same for me in 5.0.1 and 5.4 too.
     
  7. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
  8. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    I guess I'm not very good at understanding English, because I'm not getting what you said from the documentation. I always have problems understanding documentation. But its good to know its an intended behavior. I haven't noticed it before in my other projects, so I thought its a bug. Thanks. :)
     
  9. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    I took this part
    This message is sent to the trigger and the collider that touches the trigger.
    to mean that the message is sent to the GameObject containing the trigger collider. Again - could probably be written in a clearer fashion.
     
    ChrisSch likes this.
  10. ChrisSch

    ChrisSch

    Joined:
    Feb 15, 2013
    Posts:
    763
    Yeah could be it. Thanks again. :)