- Home /
How do RigidBodies and Hierarchy affect child objects' colliders?
I've been trying to get a simple object-as-button to work correctly for almost two weeks now, and I've seen some very strange (to a new user of Unity) behavior with colliders and mouse events. A good overview of my project:
You can't see it in the screenshot, but Spaceship 1 is a RigidBody. My desired functionality is to have Spaceship 1 a rigidbody, and the child objects (Central Console and Control Pedestal) to stay where they are relative to Spaceship 1. After hours of frustration trying to get my OnMouseEnter debug statement to fire, I finally bumped into these:
If I add a RigidBody component to Control Console, all mouse events work perfectly when I mouseover or click on Control Console.
If I remove the RigidBody component from Spaceship 1, all mouse events work perfectly.
If I move Control Console to the root of Hierarchy, so it's no longer a child of Spaceship 1, all mouse events work perfectly.
Question: I obviously am not understanding a few things here. I definitely need to learn more about how parent objects affect child objects, but I haven't seen anything in the Unity docs or API that suggests a parent affects colliders. Anyone have some knowledge/links they can share on this subject?
Hi, I would recommend using raycasting to detect objects under mouse and clicks. This will allow you to use physics layer masks to choose what object can be hit or not, test if one specific object is under the mouse or not anywhere in the code, have some more accurate 3D space coordinates of the point clicked so you can spawn some particles to give feedback to the player... It will also be more flexible when your project grows. There are lots of examples on the web and resources on the asset store on the subject.