• 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 francescolippera96 · Jun 01 at 10:24 AM · uieventsystempointer

PointerEnterHandler apparently not firing

Im creating an interactible computer screen with a custom pointer (by moving an ui element and raycasting from its position). I managed to get that working, and i was able to trigger the pointerDownHandler, pointerUpHandler, pointerClickHandler and the all work perfectly, but for some reason the pointerEnterHandler doesnt seem to do anything, i tried using a script from unity's UI documentation to check if the object is currently highlighted and its not, this is the script i copypasted:

 //Use the Selectable class as a base class to access the IsHighlighted method
 public class Example : Selectable
 {
     //Use this to check what Events are happening
     BaseEventData m_BaseEvent;
 
     void Update()
     {
         //Check if the GameObject is being highlighted
         if (IsHighlighted())
         {
             //Output that the GameObject was highlighted, or do something else
             Debug.Log("Selectable is Highlighted");
         }
     }
 }
 

and this is the script im using (made following this YT tutorial, although my implementation is based on direct input from the mouse, instead of how he did it taking look direction as input link text)

the input functions at the bottom are called by an input manager script, those work fine as i did get the buttons to click, its just the Highlighting that wont work for some reason

 public class ScreenCursor : MonoBehaviour
 {
     [SerializeField] RectTransform cursor;
     [SerializeField] MouseLook mouseLook;
     RectTransform canvas;
     GraphicRaycaster raycaster;
     List<RaycastResult> results;
     List<GameObject> targets;
     Rect rect;
     Vector2 mouseInput;
     bool active = false;
     bool sendMouseDown = false;
     bool sendMouseUp = false;
     bool isMouseDown = false;
 
     void Awake()
     {
         canvas = GetComponent<RectTransform>();
         raycaster = GetComponent<GraphicRaycaster>();
         rect = canvas.rect;
         results = new List<RaycastResult>();
         targets = new List<GameObject>();
     }
 
     void Update()
     {
         GetMouseInput();
         MoveCursor();
         SendInput();
         ResetBools();
     }
 
     void SendInput()
     {
         PointerEventData pointerData = new PointerEventData(EventSystem.current);
         Vector2 centeredCursorPosition = new Vector2(cursor.anchoredPosition.x + rect.xMax,
                                                      cursor.anchoredPosition.y + rect.yMax);
         pointerData.position = centeredCursorPosition;
 
         results.Clear();
         
         raycaster.Raycast(pointerData, results);
 
         foreach(RaycastResult result in results)
         {
             ExecuteEvents.Execute(result.gameObject, pointerData, ExecuteEvents.pointerEnterHandler);
 
             if (sendMouseDown)
             {
                 ExecuteEvents.Execute(result.gameObject, pointerData, ExecuteEvents.pointerDownHandler);
                 print("down");
             }
             else if (sendMouseUp)
             {
                 ExecuteEvents.Execute(result.gameObject, pointerData, ExecuteEvents.pointerUpHandler);
                 ExecuteEvents.Execute(result.gameObject, pointerData, ExecuteEvents.pointerClickHandler);
                 print("up");
             }
         }
     }
 
     void GetMouseInput()
     {
         mouseInput = new Vector2(mouseLook.mousex, mouseLook.mousey);
     }
 
     void MoveCursor()
     {
         Vector2 newPosition = cursor.anchoredPosition + mouseInput;
 
         if (newPosition.x < rect.xMin)
         {
             cursor.anchoredPosition = new Vector2(rect.xMin, cursor.anchoredPosition.y);
         }
         else if (newPosition.x > rect.xMax)
         {
             cursor.anchoredPosition = new Vector2(rect.xMax, cursor.anchoredPosition.y);
         }
         else
         {
           cursor.anchoredPosition += new Vector2(mouseInput.x, 0);
         }
 
         if (newPosition.y < rect.yMin)
         {
             cursor.anchoredPosition = new Vector2(cursor.anchoredPosition.x, rect.yMin);
         }
         else if (newPosition.y > rect.yMax)
         {
             cursor.anchoredPosition = new Vector2(cursor.anchoredPosition.x, rect.yMax);
         }
         else
         {
           cursor.anchoredPosition += new Vector2(0, mouseInput.y);
         }
     }
 
     public void OnMouseLeftPressed()
     {
         sendMouseDown = true;
         isMouseDown = true;
     }
 
     public void OnMouseLeftReleased()
     {
         sendMouseUp = true;
         isMouseDown = false;
     }
 
     void ResetBools()
     {
         sendMouseDown = false;
         sendMouseUp = false;
     }
 }
 

i spent a couple of days researching before writing this, pls show me how dumb i am and didn't notice the obvious mistake

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

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

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

Unity UI create and drag with one click 0 Answers

UI Clicking thought alpha of image 3 Answers

IPointerExitHandler while holding click 0 Answers

Enable/disable EventSystem? 2 Answers

Selectable/Button not being selected 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