Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

OnTriggerExit() called when collider gets re-parented

Discussion in 'Scripting' started by MiaoBolverk, Apr 4, 2018.

  1. MiaoBolverk

    MiaoBolverk

    Joined:
    Feb 6, 2018
    Posts:
    26
    I have an object Hand, with a rigid body attached to it. In every Update() call, the user's hand controller rotation and position are tracked.

    In my scene, there is an object Pin, with a mesh collider attached to it. Inside OnTriggerEnter() (called inside the Hand class), Pin becomes re-parented to Hand. (Pin's original parent is something else.)

    My scene also contains other objects with colliders. However, these other objects do not get re-parented -- only Pin does.

    Once this re-parenting takes place, OnTriggerExit() (inside the Hand class) is called immediately. This is surprising to me -- I had expected OnTriggerStay() (inside the Hand class) to be invoked instead.

    Is such behaviour by design? Is there an elegant way of working around such behaviour?
     
    Last edited: Apr 4, 2018
  2. Mokzen

    Mokzen

    Joined:
    Oct 10, 2016
    Posts:
    102
    Let me see if I get the situation correctly.

    You have a gameobject in your scene, which has a mesh collider attached. Is the OnTriggerEnter called from that object, or from the player/hand?
     
  3. MiaoBolverk

    MiaoBolverk

    Joined:
    Feb 6, 2018
    Posts:
    26
    It is called from the Hand class. I will update my question to make this clear.
     
  4. Mokzen

    Mokzen

    Joined:
    Oct 10, 2016
    Posts:
    102
    Hmm. I have no idea what causes this issue. Though it probably won't make a difference here, I wouldn't use a mesh collider for these purposes. I would simply use a box collider.

    I hope you find an answer. :