Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by aphenine · Nov 05, 2016 at 07:39 PM · uicanvaseventsystemevent triggering

Unity UI Events not working for Canvas objects

I'm trying to use the Unity EventSystem to handle certain parts of my interface without having to go through the EventTrigger class.

I've used the EventSystem to select items in my scene in a previous version of my code, but I wanted to take it to the next level and also do things in my interface. At the moment, I want to get edge-scrolling to work. To do that, I have a GameObjects that started out life as a Panel with the UI Sprite removed. It's orientated to the left of the screen, a child of a child of Canvas (and it's parent is full screen).

Attached to that object is this bit of code:

 using UnityEngine;
 using UnityEngine.EventSystems;
 using System.Collections;
 
 public class EdgeScroll :     MonoBehaviour,
                             IPointerEnterHandler,
                             IPointerExitHandler
 {
     public enum ScrollDirection
     {
         Up,
         Down,
         Right, 
         Left,
     }
 
     public ScrollDirection    scrollDirection;
     public InterfaceManager    IM;
 
     public void OnPointerEnter( PointerEventData eventData )
     {
         Debug.Log ("EdgeScroll: On Pointer Enter");
         switch ( scrollDirection ) {
         case ScrollDirection.Up:
             IM.scrollVertical = 1f;
             break;
         case ScrollDirection.Down:
             IM.scrollVertical = -1f;
             break;
         case ScrollDirection.Right:
             IM.scrollHorizontal = 1f;
             break;
         case ScrollDirection.Left:
             IM.scrollHorizontal = -1f;
             break;
         default:
             break;
         }
     }
 
     public void OnPointerEnter( BaseEventData BED)
     {
         OnPointerEnter (BED as PointerEventData);
     }
 
     public void OnPointerExit( PointerEventData eventData )
     {
         if (scrollDirection == ScrollDirection.Up || scrollDirection == ScrollDirection.Down)
             IM.scrollVertical = 0f;
         else
             IM.scrollHorizontal = 0f;
     }
 }
 

It doesn't work. Neither has duplicating the function and putting it through an EventTrigger instead (that's what the second version is). I don't get a call and I don't get any debug printed.Contrast this to 3D objects, for which I have managed a simple EventTrigger.

I'm trying to work out what I'm doing wrong and have looked at the Unity.UI source code, but I can't spot anything I'm not doing that something else (e.g. Button) is. I'm stumped and any help would be appreciated.

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
5

Answer by aphenine · Nov 06, 2016 at 08:56 PM

I solved this for myself.

I went back to Panel and tried adding an image, on the off-chance it would work. Lo and behold, it did, especially once I noticed the "Raycast Target" option. This then allowed me to type the right question into a search engine and it turns out my question has already been answered:

http://answers.unity3d.com/questions/1091618/ui-panel-without-image-component-as-raycast-target.html

(Short answer: The Graphics Raycaster in Canvas works only on GameObjects that have a component descended from the Graphics class (e.g. Image). As a result, all UI GameObjects won't intercept events unless they have some kind of Graphic attached.)

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

106 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 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 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 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

How to render an image always on top? Already tried some solutions 0 Answers

Player Can't Interact With UI 3 Answers

UI Button not working? 0 Answers

How to check what UI type is currently in focus 1 Answer

How do I NOT play a sound on the first selected button. 2 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