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 Bovine · Oct 21, 2012 at 02:04 PM · rigidbodyraycastcollidertriggeractive

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

Hi There

I have many UIs that occupy the same space on the screen and are hidden and shown as the game requires. Each button contains a collider (set to trigger) for that button and mouse/touch interaction is done via Physics.Raycast(). The problem I have is that when I am trying to click certain buttons that are visible, the Physics.Raycast() returns the Collider for a button who's GameObject is inactive. The UI is all in one hierarchy, the root of which contains a kinematic RigidBody with gravity off. If I remove this RigidBody, the 'hidden' colliders are no longer hit by the Raycast and it all works.

The docs are a little woolly on this - it says raycast is performed against all colliders (and presumably triggers) in the scene, and naturally there's the option to rayacst only against certain layers. It isn't explicit about behaviour against colliders on inactive GameObjects. I would however, have thought that the raycast would remain the same regardless of the RigidBody, unless the RigidBody has some intentional side-effect I am unaware of?

So what should the behaiour be? If the RigidBody is altering the behaviour, is this as expected? If so, can someone explain it, if not, can you post the link to log a bug :oD

I am using nGUI and have sought some guidance on the nGUI forums, but this feels more like a Unity issue? I am on the latest (3.6.6) Unity (Pro) and the latest nGUI. I have tried to re-create the issue in a smaller scene with no success as yet.

Thanks in advance. Bovine

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

1 Reply

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

Answer by Julien-Lynge · Oct 21, 2012 at 08:16 PM

That does sound like a bug - changing the RigidBody state changes the registration of the object with PhysX, but if a GameObject is inactive all of its components are inactive as well. Just curious - after the RigidBody has been registered with physics (e.g. after the Awake/Start function if you're adding in the editor, or a frame after you've added it at runtime), what happens if you turn on the deactivated trigger GOs and then turn them back off? Do they behave properly, or are they stuck in this mode?

You should definitely file a bug report - you can access it from the Help menu within the Unity Editor, and attach your project or specific files to the report.

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 Bovine · Oct 21, 2012 at 08:59 PM 0
Share

If I toggle the state of the offending object, or turn it's Box Collider off, it then starts to behave correctly. Yes, it's sounding more and more like a bug - I'll log one.

avatar image Bunny83 · Oct 21, 2012 at 10:17 PM 1
Share

A Rigidbody does change the behaviour of child colliders since they all belong to the rigidbody. They are kind of combined into one compound collider. See this page for more details.

Activating / deactivating a GameObject is not always a solution, some components seems like they aren't bound to the active state of the gameobject.

A collider is not a Behaviour, but it also has an enabled property. When you disable the collider it should work as you want.

avatar image Julien-Lynge · Oct 21, 2012 at 10:20 PM 0
Share

Thanks for elaborating, Bunny. Nicely said :)

avatar image Bovine · Oct 21, 2012 at 10:22 PM 0
Share

While disabling the collider does work, this behaviour doesn't seem deter$$anonymous$$istic - if I create a simple UI with two buttons, one of which is hidden while the other is visible and visa versa, if the buttons are in the same place and each has a collider, I can merrily click the visible button and show the other button and then click that to show the first.

However somewhat randomly (although always the same button) the collider on a button who's GO is hidden will be returned by the raycast. It's random in the sense that it affects some buttons but not all. If I then turn the GO on and off for the hidden button, the collider for that hidden button is NOT subsequently returned by the raycast.

avatar image MrCranky · Jan 29, 2013 at 09:29 PM 0
Share

Just wanted to chime in and say I'm seeing the exact same behaviour - multiple nGUI panels, with box colliders overlapping in space, but only one set / tree of game objects active, and yet the correct box colliders aren't triggering. Remove the rigid body component from the top level game object shared by the various panels, and the correct colliders respond.

Show more comments

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

12 People are following this question.

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

Related Questions

Unity 2D Trigger Detection is not working. 6 Answers

OnTriggerEnter mesh collider problem 1 Answer

Enemy line of sight using linecast and colliders 1 Answer

Rigidbody Trigger 1 Answer

Moving objects using raycasting? 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