Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by slkjdfv · Apr 18, 2012 at 08:44 PM · rigidbodycollidertrigger

Child objects trigger collider not working when parent has rigidbody

I have tried using OnMouseOver and a raycast mouse event using camera.screenpointtoray but I still can't get the collider to recognize when my mouse is over it if it's parent object has a rigidbody. What gives? Any suggestions/advice?

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Adamcbrz · Apr 19, 2012 at 04:09 AM 1
Share

Does your parent object have a collider. Raycast will stop at the first collider it hits. If you have some code we might be able to point out why it's not working for you.

avatar image slkjdfv · Apr 19, 2012 at 10:39 PM 0
Share

Yes it does. In my second attempt I tried using a raycast to check where the mouse is pointing. It's set to ignore layer 8 I set the parent to layer 8 not the children. No this works fine and dandy with no rigidbody attached to the parent but as soon as I attach the rigidbody it no longer works same thing happens with the On$$anonymous$$ouseOver event and no collider attached to the parent.

avatar image Adamcbrz · Apr 20, 2012 at 02:23 AM 0
Share

I think you are experiencing the effect of a compound collider. Which means children colliders of a rigidbody are treated as the rigidbodies collider. At least thats how i under stand them from the documentation.

http://unity3d.com/support/documentation/Components/class-Rigidbody.html

1 Reply

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by slkjdfv · Apr 21, 2012 at 02:36 PM

I solved it last night. It turns out OnMouseOver events will NOT not work on child objects if the root parent has a rigidbody. BUT! If you use a raycast and hit.collider.transform it does. Here's the script I used to test this(It's in C#) :

 Using UnityEngine;
 Using System.Collections;
         
 public Class AdvancedMouseDetect: MonoBehavior
 {
     public Camera myCam;
     private LayerMask _layerMask 1 >> 8; //This sets the object to ignore layer 8 which is a custom layer;
     
     void GetMouseInfo()
     {
         Ray ray = myCam.ScreenPointToRay(Input.mousePosition);
         RaycastHit hit;
     
         if (Physics.Raycast(ray,out hit, Mathf.Infinity, _layerMask))
         {
             if(hit.collider.transform.name == name)//This detects the colliders transform if you just use hit.transform it gets the root parent at least thats what I found.
             {
                 Debug.Log("Mouse is over " + name + ".")
             }
         }
     
     }
     
     void Update()
     {
         GetMouseInfo();
     }
         
 }


I hope this helps someone or every one :D

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Hoqq · Apr 15, 2014 at 08:04 PM 0
Share

I LOVE YOU. I was having the same problem and using hit.collider.transform ins$$anonymous$$d of hit.transform fixed it.

avatar image Sarseth · Dec 18, 2016 at 10:03 AM 0
Share

Thanks man...

Unity support. Can you fix your documentation if that's not a bug (i guess its not bug cause of 2 years appearacne) : https://docs.unity3d.com/ScriptReference/$$anonymous$$onoBehaviour.On$$anonymous$$ouseOver.html ?

Probably not, cause of particle system, that is the only target of this engine recently.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Should Physics.Raycast() hit a Trigger on a disabled GameObject? 1 Answer

Kinematic Rigidbody Collider not colliding with Static Trigger Collider 3 Answers

Access other collider without use of Trigger collider. 1 Answer

Box collider triggers interfering with rigidbody movement 3 Answers

Trigger Collision with Character Controller 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges