Hi,
I’ve stumbled upon a weird behaviour and wanted to know if this was normal or not.
I start with two rigidbodies (cubes) that are colliding together. I change the tag of the GameObject containing one of the colliding rigidbodies. Then I add a joint to which I attach the other rigidbody whose tag has no been changed. At that point I get an onCollision exit call from the connected body and no more onCollisionStay calls event if the rigidbodies are still touching each other. Here’s my code:
// This is called when both rigidbodies are colliding with each other.
public void JoinBodies(float jointBreakForce, GameObject otherObject)
{
// Remove this line and OnCollisionExit will not get called
otherObject.tag = "Grabbed";
m_joint = otherObject.AddComponent<FixedJoint> ();
m_joint.connectedBody = this.rigidbody;
m_joint.breakForce = jointBreakForce;
// Displaying the object's name just to make sure which one it is
Debug.Log(otherObject.name);
}
// This is called even if the rigidbodies are still touching each other.
public void OnCollisionExit(Collision c)
{
Debug.Log(c.gameObject.name);
}
If I do not change the gameObject’s tag OnCollisionExit is not called. Is this a bug? The profiler did not show any spikes in physics when the tag was changed.