Subcollider Independent of Rigidbody

One of my rigidbodies has a child collider that I would like to send mouse events to, but its OnMouseWhatever() functions are being forwarded because it’s considered part of a compound collider. Is there a way I can individuate input from just this one collider?

You could make it behave like a child but not actually be one, except then it wouldn’t collide as a part of the rigidbody.

I tink you can set the collider’s attachedRigidbody to null. Like Yoggy said, it will no longer affect physics (and may collide with your other colliders unless you use Physics.IgnoreCollision to make it not collide with them). Or, you can make a second, separate, trigger collider to be used for OnMouseWhatever calls.

I’ll give attachedRigidbody and IgnoreCollision() a look. Triggers don’t call the OnMouse functions, do they?

For some reason, setting gameObject.collider.attachedRigidbody = null produces a MissingFieldException (cannot find variable attachedRigidbody). However, Debug.Log(gameObject.collider.attachedRigidbody) prints fine to the console.

What’s going on here?

:?

I guess it doesn’t like you ripping the collider off the body like that. The error is probably the rigidbody saying “hey, where did my collider go?”

attachedRigidbody is a read only property.

If your code was going through statically typed code path you would get a compile error. Since it is getting duck typed you get a runtime error that there is no setter function for the attachedRigidbody property.

The attachedRigidbody is always implicit by parenting. Yoggy’s suggestion of keeping it seperate but moving it relative to a some other transform using a script seems like a good solution.

Alternatively, just do the raycast from the camera yourself.

Alright. Will do. Thanks for helping me, guys.