Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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
3
Question by Barrett-Fox · Mar 06, 2011 at 02:48 AM · rigidbodykinematiconmouseovertooltiponmouseenter

Presence of rigidbody on parent stops OnMouseEnter in a child collider

I'm working on a simple 3D tooltip that uses a box collider. But the hierarchy containing the tooltip gets parented to an object with a rigid body. This kills the OnMouseOver and OnMouseEnter events for my child collider (Though, Update functions in the child's script still work fine). If I Destroy the rigid body on the parent, OnMouseOver on my child comes back to life. Tried disabling various properties of the rigidbody. Didn't help.

Is there a way to work around this? Is there a better way to do this?

var card : GameObject;

function Start () { card.SetActiveRecursively(false);

}

//this part works after parenting - using it to verify script is working

function Update () { if (Input.GetKeyDown ("o")) { card.SetActiveRecursively(true); } if (Input.GetKeyDown("i")) { card.SetActiveRecursively(false);

 }

}

//this part stops working after parenting function OnMouseEnter () { //activate the card Debug.Log("MouseEnter"); card.SetActiveRecursively(true); }

function OnMouseExit () { //deactivate the card Debug.Log("MouseExit");

     card.SetActiveRecursively(false);

}

Comment
Add comment
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

2 Replies

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

Answer by laurent · Mar 23, 2011 at 05:29 AM

RigidBody swallow all child collider event. Add a rigid to your tooltip and switch it to kinematic. Or if you don't want to burden the physics with extra rb, add a script to your existing rigid

void OnMouseEnter()
{
   BroadcastMessahe("OnMouseEnter");
}

Comment
Add comment · Show 6 · 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 Barrett-Fox · Mar 23, 2011 at 05:53 AM 0
Share

Hey this worked!! Added a kinematic rigidbody to the child object that had the tooltip and Voila!

Thanks very much!

avatar image Nik · Apr 13, 2011 at 01:50 PM 0
Share

@laurent: I like ask how would adding rigids to the child colliders burden the physics? If say the parameters (such as mass) of these 'new' rb are reduced to $$anonymous$$imum, they will not affect the overall physics, right?

avatar image Barrett-Fox · Jun 06, 2011 at 06:35 PM 0
Share

@Nik maybe this should be its own question. Would be good to have that informatation.

avatar image goguen-alex · Feb 07, 2017 at 07:06 PM 1
Share

"GameObject.Broadcast$$anonymous$$essage: Calls the method named methodName on every $$anonymous$$onoBehaviour in this game object or any of its children." - wouldn't broadcasting the message create an infinite loop with itself?

avatar image Tom-Mensink goguen-alex · Sep 02, 2018 at 10:19 AM 0
Share

Yes it would. To only call it on the children I added this method. The option of adding a dummy rb worked too, yet disabled the options to collide in my code somehow.

         // Rigidbody swallows all mouse events. So to transfer the On$$anonymous$$ouseDown event (others to be added when necessary) downwards, add a broadcast to all childs
         // Alternative is to add a dummy RigidBody (kinematic = checked) on the objects needing to receive mouse events, but this disables the collision effects somehow
         public void On$$anonymous$$ouseDown()
         {
             var children = gameObject.GetComponentsInChildren<Transform>();
             foreach (var child in children)
             {
                 if (child.transform != this.transform)
                     child.gameObject.Broadcast$$anonymous$$essage("On$$anonymous$$ouseDown", options: Send$$anonymous$$essageOptions.DontRequireReceiver);
             }
         }
   
avatar image IC_ · Aug 07, 2019 at 12:06 AM 0
Share

Thanks for the infinite loop

avatar image
1

Answer by Tom-Mensink · Sep 02, 2018 at 10:26 AM

Adding this to the highest level with the rigidbody attached works. You can replace OnMouseDown with OnMouseEnter of course.

     public void OnMouseDown()
     {
         var children = gameObject.GetComponentsInChildren<Transform>();
         foreach (var child in children)
         {
             if (child.transform != this.transform)
                 child.gameObject.BroadcastMessage("OnMouseDown", options: SendMessageOptions.DontRequireReceiver);
         }
     }
 

Comment
Add comment · 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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Kinematic rigidbody movement. 2 Answers

Moving a kinematic object a fixed distance over a set time with physics in mind 2 Answers

Having a kinematic rigidbody detect collision with a collider without a rigidbody 7 Answers

Kinematic Rigidbody Collider not colliding with Static Trigger Collider 3 Answers

Whenever I add a rigidbody and collider to my player, it interferes with the movement script and makes it teleport 1 Answer


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