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
5
Question by Michael CMS · Nov 01, 2012 at 08:51 PM · raycastlayersonmouseover

Custom layer to be ignored by OnMouseOver ?

Hello,

I need to create a layer that will be ignored by OnMouseOver but it won't be ignored by Raycasts. Is this possible ?

My problem comes because of the following scenario :

I have a planet and I'm using a sphere collider to encapsulate all of the planet + landscape. However some landmarks are interactive, but because the sphere collider is bigger the OnMouseOver function is no longer called.

I need the sphere collider for various actions which involve raycasts. If I move the planet to the IgnoreRaycast layer, the landmarks are clickable but I bellive I cannot raycast to that layer (or I didn't use the right mask for the IgnoreRaycast layer ).

Any tips ? Anyone ?

Comment
Add comment · Show 4
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 AngryCSharpNerd · Nov 08, 2015 at 02:00 AM 0
Share

Please, I need this too.

avatar image JoshuaMcKenzie · Nov 08, 2015 at 04:14 AM 1
Share

It depends on how you are using On$$anonymous$$ouseOver and what Layers you are already using. Are you using the Eventsystem object? Are you manually writing your raycasts via Phyics.Raycast() to emulate On$$anonymous$$ouseOver, or are you using the On$$anonymous$$ouseOver Function that comes with the $$anonymous$$onoBehavior?

After fiddling with all these options, my personal preference is using the EventSystem as it gives you so much control over all sorts of raycasting (from the camera) and access to all the fun pointer events (including OnPointerEnter, which is similar to On$$anonymous$$ouseOver but works for both PC and Tablet).

Do you ever need to use mouse events on the Planet's collider itself or are they raycasts independent from the camera's position? If they are independent then you can easily place the planets collider on an entirely different collision layer and just have your On$$anonymous$$ouseOver Raycaster mask that layer

(if via the EventsSystem it'd be a layer you remove on the GraphicsRayCaster Component that you would have to attach to your camera)

the exact answer I can give just depends on how you're doing it in your game. can you show some code and what layers you have?

avatar image Harinezumi JoshuaMcKenzie · Nov 10, 2015 at 10:12 AM 0
Share

I am in a very similar situation, I would like my raycasts for On$$anonymous$$ouseEnter ignore some colliders.

I'm using the EventSystem, and I would like the On$$anonymous$$ouseEnter ignore the collider of the player object (on the Player layer). I cannot turn off the collider of the player, because that would cause all kinds of problems.

I think I would need what you mentioned, remove the layer from the GraphicsRaycaster component on the main camera, but I don't understand what you mean. Could you explain it in a bit more detail?

EDIT: O$$anonymous$$, now I understand what you mean: add a raycaster to the main camera (type depends on your game), and set the event mask to whatever layers I want to ignore. This would be nice, except raycasts don't work well with a Character Controller script, they still get blocked. Anyway, thanks for the info!

avatar image JoshuaMcKenzie Harinezumi · Nov 10, 2015 at 01:45 PM 1
Share

if that script were to be on a UI element like a button, then you would need a Graphics raycaster on the parent canvas with the event mask set to the same layer the script is set to. however if the script is on a 3d game object ins$$anonymous$$d you need a Physics Raycaster on the Camera (its a different component). Theres also a Physics 2D raycaster as well for 2d elements

in both cases you'll need an Event system gameobject, which it sounds like you have. and finally you need to have your script, your character controller, listen to the right calls. When using the Event system you will want to use OnPointerEnter ins$$anonymous$$d of On$$anonymous$$ouseEnter. Look into the Event System documentation to learn more about it. however the documentation is lacking a little in example code as far as the pointer handlers are concerned so this should help you start out

 using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class CharacterController: $$anonymous$$onoBehaviour, IPointerEnterHandler
 {
 
 
     public void OnPointerEnter (PointerEventData eventData)
     {
         Debug.Log("entered: " + gameObject);
     }
 
 }

if you want you raycasts to ignore certain colliders make sure they are on separate layers and have the Phycis/Graphics Raycaster only focus on specific layers. and you can use code to swap that out whenever you want.

0 Replies

· Add your reply
  • Sort: 

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

13 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 avatar image

Related Questions

function OnMouseOver() ignore selected raycast 1 Answer

ignore raycast layers problem 1 Answer

How do I use layermasks? 9 Answers

Layer mask doesn't work... 1 Answer

Use OnMouseOver or Raycasting while also displaying a camera texture. 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