Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Ignoring layers in UnityGUI

Discussion in 'Immediate Mode GUI (IMGUI)' started by Nihao, Oct 6, 2014.

  1. Nihao

    Nihao

    Joined:
    Oct 22, 2012
    Posts:
    13
    I am trying to ignore an Image component overlay (rendered last) so I can trigger events underneath (rendered earlier).

    I thought that I might use the GraphicRaycaster for that by putting the overlay on a different layer and setting the raycaster but I can't get that to work (setting BlockingObjects and BlockingMask doesn't seem to help). I can disable the overlay Image component and then everything works as intended but that obviously is not the solution.

    For example, imagine I have a glass-imitating transparent overlay texture over my UI and I would like to intercept the events not on the glass but on the components below the glass.

    So how do I ignore the overlay and let the event system receive events on GOs rendered earlier?

    I am using Unity 4.6b20. Thank you!
     
  2. benbonso

    benbonso

    Joined:
    Oct 29, 2012
    Posts:
    7
    me to
     
    Nihao likes this.
  3. Tiltar

    Tiltar

    Joined:
    Mar 20, 2014
    Posts:
    1
    Bump, I'd like this too and haven't found anything so far in the docs. Anybody have ideas?
     
  4. Nihao

    Nihao

    Joined:
    Oct 22, 2012
    Posts:
    13
    One way I have found so far is to use the CanvasGroup where you can untick Interactable and Blocks Raycasts.
     
    Last edited: Nov 7, 2014
  5. Nihao

    Nihao

    Joined:
    Oct 22, 2012
    Posts:
    13
    And another solution is through script by implementing the ICanvasRaycastFilter interface. You can then decide to either block the raycast or not.

    E.g.:
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class PassUIRaycast : MonoBehaviour, ICanvasRaycastFilter
    5. {
    6.     public bool IsRaycastLocationValid(Vector2 screenPoint, Camera eventCamera)
    7.     {
    8.         //the raycast will continue, if you want to block then set to true
    9.         return false;
    10.     }
    11. }