OnTriggerExit2D called when FixedJoint2D is added

I have this weird behaviour when I want something to grab onto an area.

Setup, Unity 2021.3.20f1.

  • Area:

  • BoxCollider2D (isTrigger = true)

  • Rigidbody2D (Kinematic or Static)

  • Grabby:

  • CircleCollider2D (isTrigger = false)

  • Rigibody2D (Dynamic)

With just these, when I debug the OnTriggerEnter and Exit events, I get the following:

  • “Throw” the Grabby into the Area → OnTriggerEnter
  • e.g. Pause the Editor, add a FixedJoint2D to Grabby (Connected RG is the Area)
  • continue into PlayMode → OnTriggerExit is called, although the object is still within the Trigger
  • (The same happens when I put the FixedJoint on the Area and Connected RG is Grabby)

Is this the desired behaviour?

Yes if Joint2D.enableCollision is off.

You say FixedJoint2D but if the above is off, it’ll be the same for any 2D joint and any trigger/non-trigger combination. It’s saying they should not interact.

Thanks for your quick anwser!
Now it seems to work. The wording of enableCollision had me thinking it has nothing to do with triggers.

Unity uses “collision” everywhere as a generic term covering both and whilst I’ve never really liked it, it’s what has been for a very long time. This is why we have a “Layer Collision Matrix” to define what can interact.

For many years though, we’ve moved towards using the much more appropriate word “contact” but legacy properties and features still use “collision” and the benefit of changing all of those now isn’t great.

For many, a “trigger” is a type of “collision” but personally, “contact” is a better word for both.

1 Like