Compound Collider Pattern in Object Hierarchy (2D)

Hello, I’m a bit new to the Physics stuff. I have a gameobject built of 2 child gameobjects, with a hinge and spring joint between them. To make that work, they have RigidBodies attached to each.

At the parent level, I have collision detection code in place that normally would work fine in a Compound Collider scenario. However, due to the rigidbodies in my child objects, the Collision messages are not being propogated to the parent.

I’m starting to consider some “hacky” solutions as a way around it. However, I am certain this must be a common problem that has an optimal pattern for solving it, and I’m just not seeing it. With a complicated object requiring RigidBodies for joints, how does one centralize code for handling collision detection for the object overall?

You can’t explicitly control where the callbacks go, they implicitly go to both colliders involved in the contact as as well to any attached rigid-body assuming it’s not on the same GameObject.

Right now, there’s no events you can hook into which would potentially be a better solution.

If you have some custom calling pattern, you’re probably better off performing those from the child and calling into the parent.

Fair enough. I ended up working out an alternative that was similar to catching it in the children, and then calling it on the parent. But, it’s much better to simply avoid it.

When I learned about CompoundColliders (which I did not see in the manual, btw), I thought it was an interesting idea regarding inheritance. It would be interesting to have child objects’ components generate events that the parent would have visibility to and decide to catch and even override.

Anyways, thanks for getting back to me on the question.

A compound collider is where multiple colliders attach to a single rigidbody which can be anywhere anywhere up the parent hierarchy and contact messages work just fine that way. This parent-attachment is obviously done implicitly.

The problem comes when you add multiple rigidbody in a hierarchy and expect contact-events from that rigidbody and its colliders to somehow be sent to arbitrary other GameObjects (possibly in parents).

Doing all this with events is something that is certainly for the future and will happen.