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
2
Question by Pangamini · Oct 03, 2014 at 09:26 AM · raycasteventsystem

How to let handled events / raycasts pass through

First, i really appreciate the way unity team is going with design decision. Looks like they finally started using interfaces and let us override core classes more. But to the problem:

I am using new EventSystem and my GO has a script which implements EventSystems.IPointerClickHandler attached. I am receiving mouse click events. But what i'd like to do, is to optionally let this raycast pass through (after the event is handled), based on the event handler result.

An example would be an object with alpha cut texture. I want to apparently ignore clicking on transparent parts (and let objects behind being clicked on instead), but this decision (whether object with alpha texture was hit or not) should be done by the object itself.

Does the EventSystem or other classes involved support this behaviour?

If not then: I guess i will have to re-raycast with the object being ignored, in that case, is there some way how to invoke the same raycast?

Edit: I've noticed that BaseRaycaster.Raycast works with a list of hit objects; in that case, re-raycasting seems redundant and this should be possible to resolve other way?

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
0
Best Answer

Answer by Pangamini · Oct 03, 2014 at 01:11 PM

So i solved this by deriving from the PhysicsRaycaster class

Raycaster first checks the hit gameoObject for components with my IRaycastFilter interface and if it finds some, it will call a method on it, giving it a chance to discard this gameObject from hit list

Since this is still in beta, there's no documentation and no source codes, so i had to use .net reflector to see how the raycaster should work

Comment
Add comment · Show 3 · 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 invadererik · Feb 27, 2015 at 10:36 AM 0
Share

Any chance you could share this script ? I'm trying to do similar.

avatar image Pangamini · Feb 27, 2015 at 11:17 AM 0
Share

Well here it is, but it's quite old now, written in older version of unity so i am not sure if it still works (i am not using it right now)

 import UnityEngine
 import UnityEngine.EventSystems
 
 class $$anonymous$$yPhysicsRaycaster (PhysicsRaycaster): 
 
     override def Raycast(eventData as PointerEventData, resultAppendList as System.Collections.Generic.List[of RaycastResult] ):
     
         if (self.eventCamera != null):
         
             ray = self.eventCamera.ScreenPointToRay(eventData.position)
             distance = self.eventCamera.farClipPlane - self.eventCamera.nearClipPlane
             arr = Physics.RaycastAll(ray, distance, self.finalEvent$$anonymous$$ask)
             
             if (arr.Length > 1):
             
                 comparision = def(one as RaycastHit, two as RaycastHit):
                     return one.distance.CompareTo(two.distance)
                     
                 arr.Sort[of RaycastHit](arr, comparision)
             
             if (arr.Length != 0):
                 
                 eventData.worldPosition = arr[0].point
                 eventData.worldNormal = arr[0].normal
                 index = 0
                 length = arr.Length
                 while (index < length):
                     
                     filters = arr[index].collider.gameObject.GetComponentsInParent(IRaycastFilter)
                     
                     if CheckAllFilters(filters, arr[index]):
                         
                         item = RaycastResult()
                         item.gameObject = arr[index].collider.gameObject
                         item.module = self
                         item.distance = arr[index].distance
                         item.index = resultAppendList.Count
                         
                         resultAppendList.Add(item)
                     index++
                 
             
     def CheckAllFilters(filters as (Component), raycast as RaycastHit):
         
         if filters.Length == 0:
             return true
         
         for filt as IRaycastFilter in filters:
             if filt.FilterRaycast(raycast):
                 return true
                 
         return false
             
     
 
avatar image Pangamini · Feb 27, 2015 at 11:18 AM 0
Share
 import UnityEngine.EventSystems
 
 interface IRaycastFilter(): 
 
     def FilterRaycast(physHit as RaycastHit) as bool



Here you need to implement this interface in your component and override the method so it returns true when the object is to be hit (use raycasthit data to find the pixel color or whatever you want)

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

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

Related Questions

Where did EventSystem.GetCurrentPointerData go? 1 Answer

Make element recieve camera raycast, but not block it 0 Answers

uGUI clicks going into gameobject raycasts 0 Answers

I need the x, y, z position value of the point of gaze input (pointer click in google vr) on a plane centered at (0,0,0) and scaled (2,2,2), 0 Answers

Different between IPointerClickHandler.OnPointerClick and MonoBehaviour.OnMouseDown 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