Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

IPointerEnterHandler and IPointerExitHandler not working in RC1

Discussion in 'UGUI & TextMesh Pro' started by Burve, Nov 10, 2014.

  1. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    Before, at least in 19, since 20 and 21 was really buggy, when I used IPointerEnterHandler and IPointerExitHandler interfaces and just moved my mouse around it worked perfectly (reacted when I enter or exit given area, mostly Image), however now when I moved from 19 to RC1 it seems, that mouse click is required to both event to trigger.

    So, if I just start game and do nothing both events will not react. If I click with mouse anywhere in Game view it will react. If I press any key on keyboard reaction will stop until I do mouse click.

    Is there some change somewhere I need to do to make both handlers to work properly or that is a bug (I did submit it as bug)

    I attached rar with my project, that have One scene with simple scrip, that change color of image to red if inside and blue if outside.

    Any ideas how to fix that if that is not Unity bug ?

    Update ...
    It seems it is a bug, since Unity Bug report confirmed this as bug.

    In a mean time, it seems back to B19 for me until that is fixed :(
     

    Attached Files:

    Last edited: Nov 10, 2014
  2. nia1701

    nia1701

    Joined:
    Jun 8, 2012
    Posts:
    74
    I'd also like to just add to this that in B20 for me IPointerEnterHandler and IPointerExitHandler worked great, but now with RC1 their PointerEventData is now null. Is this the same bug?
     
  3. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    hmm, can or cannot, since I did not even check what is in that PointerEventData, all I had was

    Code (CSharp):
    1.     public void OnPointerEnter(PointerEventData eventData)
    2.     {
    3.         _image.color = Color.red;
    4.     }
    5.  
    6.     public void OnPointerExit(PointerEventData eventData)
    7.     {
    8.         _image.color = Color.blue;
    9.     }
    and even tat did not trigger until I click somwhere
     
  4. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    id file a bug report so we can take a look
     
  5. nia1701

    nia1701

    Joined:
    Jun 8, 2012
    Posts:
    74
    sounds good, didn't want to flood the bug reports if it was already reported.
     
  6. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    It is Case 646787 in Unity bug systems.
     
  7. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    @Burve thats weird because in my game its working.
     
  8. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    @meapps are you sure you did not click before using that action, since it is working, but you need to perform mouse click even after any key press, if you do not do click it is not working (check attached demo)
     
  9. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    its a bug you are right its only working because i trigger it with the drag first etc....
     
  10. OneThree

    OneThree

    Joined:
    Oct 28, 2011
    Posts:
    181
    Just chiming in to say that I also ran into this bug. In Beta 20, my PointerEnter and PointerExit events worked perfectly.

    In RC1, I have to click with the mouse before those events work.
     
  11. valhalla_cats

    valhalla_cats

    Joined:
    Jan 27, 2013
    Posts:
    16
    I have the same error.
     
  12. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    hmm, I feel, that is this is true uGUI just lost it's value to me and I will be moving back to OnGUI() and ignoring mobile application, as I did before :(

     
    Last edited: Nov 13, 2014
  13. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    We are working on a fix. We will get back to you once done.
     
  14. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
    So this wasn't really a bug but a design change we made in b20 for how we wanted selection to work. In the old version what happened was that when you moved the mouse selection reverted to the mouse, and canceled any keyboard focus. This was really bad because if you were typing in an input field and then bumped the mouse it would lead to the input being unselected.

    The correct way to handle this is to allow separate states for hover and selected, and I've made a fork of the OS repo for this (follow the instructions on the landing page for how to use this):
    https://bitbucket.org/stramit/ui/branch/case-646787

    Alternatively if you just want the old behavior grab this branch:
    https://bitbucket.org/stramit/ui/branch/InputModuleOldBehaviour
     
    rakkarage likes this.
  15. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    hmm, Interesting, I did not try to work with keyboard focus (except for search field), and did not see any problems, maybe just not noticing.

    One of the example I used (maybe not the best usage oh this functionality) was to allow user to move around in FPS mode, rotate and still have mouse active, so I created 2 areas on the sides and when player moved mouse inside there screen rotated, while he can still move around with AWSD keys. In RC1 (from B19) that was not working, since after each key press I needed to click back with mouse.
    in similar way was broken my double click code (however there was no key input).

    As for repositories, maybe I did something wrong with SourceTree, but I got error
    On both repositories
     
  16. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,181
  17. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    Awesome, that first option worked, at least I just needed one click to set focus to application and then key input did not break it.

    Now just my question is - how this will work with next RC or proper 4.6. I assume manually rewriting dll's is not a really long term solution.

    As for uGUI buttons missing hover state, can't you , worst case, just leave both options open for devs, so I can choose either one that will loose focus on key input, but always will work or one, that need specific focus, or this one with missing hover feature. King of giving option to devs is better then internally setting only one and then rest have less flexibility
     
  18. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    Rc2 is out and your original system is back - it seems I will be needing Unity source code every time with every update, since UI is not usable in current state :(
     
  19. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    Yes currently how the custom dll's that are built get read are based upon the unity release number. So every release we do you'll have to pull and build the code. We did this atm to make it easier for use to determine bugs that were possibly created by the user in there own version of the ui.dll and to prevent a old version of the dll being used to report a issue we might have already fixed.
     
  20. OneThree

    OneThree

    Joined:
    Oct 28, 2011
    Posts:
    181
    Is having to rebuild dll's with every release the permanent solution to this issue? Or just a current workaround in the beta?
     
  21. phil-Unity

    phil-Unity

    Unity UI Lead Developer Unity Technologies

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    We are talking about that very issue. the last thing we want is to add more work for ourselves by people submit fixed bugs due to them using a older custom built version. We also understand the annoyance of having to pull and build with every release (although wont be as bad as there wont be as many releases as beta has).
     
  22. OneThree

    OneThree

    Joined:
    Oct 28, 2011
    Posts:
    181
    Are there any runtime workarounds that might work? Perhaps something we can call in script to spoof a mouse click or set which input (mouse vs. keyboard) to be listening for?

    Long-term, it seems like a good solution would be to simply give control to the dev over what the UI system should be listening to, so that we can at least set the state on a per-element basis.
     
  23. OneThree

    OneThree

    Joined:
    Oct 28, 2011
    Posts:
    181
    I noticed that the 4.6. RC3 notes have this:

    "UI: Change the default mode of the Standalone module to be Mouse as it allows both mouse + KB at the start of a scene load."

    Is that related to the issue in this thread? When I play my game in 4.6 RC 3 standalone, I still have to click into the UI once to get it to recognize mouse hover events.
     
  24. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    There is a way to deal with this problem if you don't want to have custom build, however it involve having separate axes for UI and player navigation or just killing UI navigation with keys at all, this what I sad on another thread about same problem

     
  25. OneThree

    OneThree

    Joined:
    Oct 28, 2011
    Posts:
    181
    Thanks for the tip!
     
  26. Aiursrage2k

    Aiursrage2k

    Joined:
    Nov 1, 2009
    Posts:
    4,835
    Im trying to create a simple vending machine to buy items for my game and i want to have it selected when you mouse over the UI. Wanting to copy heavy bullets

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.EventSystems;  // needs to be imported
    4. using UnityEngine.UI;
    5.  
    6. public class HoverEvent :   MonoBehaviour, IPointerEnterHandler, IPointerExitHandler  {
    7.     private ColorBlock m_color;
    8.     private UnityEngine.UI.Button m_button;
    9.     public void Start()
    10.     {
    11.         m_button = gameObject.GetComponent<UnityEngine.UI.Button>();
    12.         m_color = m_button.colors;
    13.  
    14.     }
    15.     public void OnPointerEnter(PointerEventData eventData) {
    16.  
    17.         Debug.Log("POINTER ENTER");
    18.         ColorBlock cb = m_color;
    19.         cb.colorMultiplier = 2f;
    20.         m_button.colors = cb;
    21.  
    22.     }
    23.  
    24.     public void OnPointerExit(PointerEventData data) {
    25.         m_button.colors = m_color;
    26.     }
    27. }
    28.  
    Well anyway i used the old for now.
    Code (CSharp):
    1.        
    2.  private HoverEvent m_hover;
    3.         void Update () {
    4.             Ray r = Camera.main.ScreenPointToRay(Input.mousePosition);
    5.             RaycastHit rch;
    6.             if(Physics.Raycast(r,out rch))
    7.             {
    8.                 if(m_hover)
    9.                 {
    10.                     m_hover.OnPointerExit();
    11.                 }
    12.                 m_hover = rch.collider.gameObject.GetComponent<HoverEvent>();
    13.                 if(m_hover)
    14.                 {
    15.                     m_hover.OnPointerEnter();
    16.                 }
    17.  
    18.             }else{
    19.                 if(m_hover)
    20.                 {
    21.                     m_hover.OnPointerExit();
    22.                 }
    23.             }
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.     using UnityEngine.UI;
    4.  
    5. public class HoverEvent :   MonoBehaviour  {
    6.     private ColorBlock m_color;
    7.     private UnityEngine.UI.Button m_button;
    8.     public void Start()
    9.     {
    10.         m_button = gameObject.GetComponent<UnityEngine.UI.Button>();
    11.         m_color = m_button.colors;
    12.  
    13.         RectTransform rt = gameObject.GetComponent<RectTransform>();
    14.         BoxCollider bc = gameObject.AddComponent<BoxCollider>();
    15.  
    16.         bc.extents = new Vector3( rt.rect.width*0.5f,rt.rect.height*.5f,1f);
    17.    
    18.     }
    19.     public void OnPointerEnter() {
    20.         // Do stuff when object is touched/clicked
    21.  
    22.         Debug.Log("POINTER ENTER");
    23.         ColorBlock cb = m_color;
    24.         cb.colorMultiplier = 2f;
    25.         m_button.colors = cb;
    26.  
    27.     }
    28.    
    29.     public void OnPointerExit() {
    30.         // do stuff when touch/click is released
    31.         m_button.colors = m_color;
    32.     }
    33. }
    34.  
     

    Attached Files:

    Last edited: Dec 18, 2014