Can I have a single rigidbody2d that acts as both collider and trigger?

I’m new to unity, and am having what I’m sure must be a simple design issue. I would like my character (a rigidbody2D attached to a couple of collider2Ds) to collide with one set of objects, set A, all of the time, and another set of objects, set B, only some of the time. But even when my character is “not colliding” with set B, I need to know if it is in contact with any member of set B.

Is there a good approach to achieving this within unity’s 2D tools?

I’ve tried layer-based collision detection, changing my character back and forth between a layer that collides with both sets and a layer that collides with only set A. But this method won’t tell me when my character is touching (but not “colliding” with in the physics) set B.

I’ve tried changing the colliders on my character to triggers, but then they don’t collide (physically) with set A.

I’ve tried making a child character that only acts as trigger, but for some reason (possibly because it contains a rigidbody2D of its own) it lags behind the parent character. Creating a parent character and using it to control two sibling characters (one set to ‘trigger’, one not) had similar spacial issues.

If code is helpful, I can copy it over, but really I think I’m just looking for an algorithm or collision detection tool for a very specific scenario. Thanks for any help!

This is a very interesting question.

Initially I would change all the colliders for set B to be triggers when the character is no longer supposed to collide with them, but this may brake other things in the scene depending on your game (other things will not collide with set B either).

Your suggested solution with a child GameObject is on the correct path. A child GameObject however does not need to have a rigidbody in order to be triggered. So do the same except do not add a rigidbody.

1: Create two layers, one that will collide with Set A and Set B, and another that will only collide with Set B.

2: Set the main character GameObject to the first layer and a collider with collision.

3: Create a child GameObject for the character, set it to the second layer and attach a collider set as trigger.

4: To the child GameObject add a script that handles the OnTrigger events.

Now when the character is no longer supposed to collide with Set B, change the layer to be the second layer. Change it back to the first layer again when it is supposed to collide with Set B.

Again this is your own solution just without the Rigidbody on the child GameObject.