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.
In OnTriggerEnter()
(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()
(in the Hand
class) is called immediately. This is surprising to me -- I had expected OnTriggerStay()
(in the Hand
class) to be invoked instead, since Hand
is still in contact with Pin
.
Is such behaviour by design? Is there an elegant way of working around such behaviour?
UPDATE:
In response to this comment:
Does the pin object have a parent before it becomes a part of the hand?
Yes. As mentioned in my post, Pin
's original parent is something else.
Or is it placed inside another collider? And does the pin leave any of these collider areas when the parenting takes place?
As mentioned in my post, Pin
itself has a mesh collider component attached to it. Perhaps I am not understanding the question correctly...
You can prevent the hand's script from getting this OnTriggerExit by adding a seperate rigidbody to the pin.
I added a separate rigid body to the pin (setting isKinematic
to true
), but OnTriggerExit()
inside the Hand
class is still called immediately after Pin
gets re-parented.
MORE INFORMATION:
Pin
's original parent (before it gets re-parented toHand
) does not itself have a collider component.- When
OnTriggerExit(Collider collider)
gets called immediately after the re-parenting takes place, thecollider
argument passed to the method is thePin
itself.
isKinematic
totrue
), butOnTriggerExit()
is still called in theHand
class. \$\endgroup\$ – user112729 Apr 4 '18 at 11:06