Search Unity

OnPointerEnter, Highlight state not working until mouse click

Discussion in 'UGUI & TextMesh Pro' started by bdream, Nov 15, 2014.

  1. bdream

    bdream

    Joined:
    Apr 25, 2014
    Posts:
    13
    Hello,

    I noticed that OnPointerEnter callback or Highlight state are not working when a scene is loaded until a there is mouse click. After the mouse click, it works perfectly fine.

    For example, take the example project and load the "Menu 3D" scene. The 3D panel is orienting according to the mouse position. But the highlight state of the button is not working: when I go over the button with the mouse pointer, it is not highlighted). After a mouse click, the "continue" button is not selected anymore and everything is working fine. There is the same issue with the OnPointerEnter callback.

    My question is: is it the normal behavior or not ? I find it confusing for the user. For me, the highlight state should be working any time, and not only after a mouse click.

    Maybe I missed the documentation on this point. In this case I'm sorry; maybe you can give me the link. Anyway, if there is a workaround for this, I'm looking for it.
     
  2. Link538

    Link538

    Joined:
    Jan 25, 2013
    Posts:
    15
  3. KnuckleCracker

    KnuckleCracker

    Joined:
    Dec 27, 2011
    Posts:
    81
    It might be related to Navigation in some way. I see the above problems and also note that if you press an arrow key or WASD, you get similar results. For instance, just add a button to a scene and run. Click the scene (as noted above) then mouse over the button. You get the highlight state. Now press an arrow key then move the mouse away from the button. The highlighted state will remain. Note that setting Navigation to "none" for the button doesn't affect this.

    I encountered all of these problems when I was trying to make a panel that swings in from the side of the screen (rotates on the Y axis). I made a panel, added an EventTrigger script, then set a trigger for Pointer Enter and Pointer Exit. Each calls Animator.SetTrigger on an animation that will rotate the panel about the Y axis to swing it in and out. Anyway, I first noted I have to click the game before I get any pointer enter and exit events. Then I started playing my game (where I use WASD a good bit) and as soon as I hit a WASD key, the panel would rotate out (because the Pointer Exit event is firing). Thinking, "oh this is some Navigation thing". I went and turned off every button's navigation. But no joy...

    I've been using unity 4.6 and the new UI for a total of 12 hours now, so I figured it was just me being dumb (and it may be).
     
  4. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
  5. meapps

    meapps

    Joined:
    May 21, 2013
    Posts:
    167
    @Burve its not a feature! in B21 its working....
     
  6. bdream

    bdream

    Joined:
    Apr 25, 2014
    Posts:
    13
    I agree, it cannot be a feature. I also filled a bug report. I hope they will fix this in rc3.
     
    meapps likes this.
  7. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    it how the system works at the moment. when highlighting is not working its due to the system being in Keyboard mode and expecting keyboard events. Once a click is received it switches back to mouse. So yes currently its a feature, take a look at the thread Burve posted for a solution for now if you want. We are working on a better solution but it will not get merged into the RC due to the high risk of the change (it touches a lot of the event code base).
     
  8. KnuckleCracker

    KnuckleCracker

    Joined:
    Dec 27, 2011
    Posts:
    81
    As an example, when a game starts none of the mouse over states (highlighted states) of the main menu buttons will work until the user clicks somewhere first? This is true even if navigation is set to 'None' on everything possible?

    Of course the first thing player's usually click is the "Play" button or something like that on a main menu, so they will only see highlighted states of buttons when/if they return to the main menu and if the game didn't use the keyboard for control and hence put the UI back in 'keyboard' mode (even though navigation is set to 'none' on everything).

    So, for me this means:

    - Don't use highlighted button states for anything. For in-game UI, player's will only see them if they have clicked last, not pressed a 'movement' key last. I have UI in my actual game that you can click, and you can use the keyboard for control of the _game_. Think RTS where you click on buttons and stuff, but you can also use the arrow keys to pan the map around.

    - Don't use pointer enter and exit events for anything. I'll have to instead do something manual (raycast, screen mouse position, etc.). Pointer exit events seem to fire as soon as someone hits WASD/Arrow (or whatever is defined in the input manager).
     
  9. phil-Unity

    phil-Unity

    Unity UI Lead Developer

    Joined:
    Nov 23, 2012
    Posts:
    1,226
    The one fix we did for RC3 was to make it start in mouse mode so you'll get the mouse events by default. If the user then tries to use keyboard navigation they will have to click again to get the hover back.
     
  10. KnuckleCracker

    KnuckleCracker

    Joined:
    Dec 27, 2011
    Posts:
    81
    That at least helps the "main menu" issue that would likely be very common.

    Now, given 4.6.0 is apparently done I've been looking for workarounds regarding Navigation and keyboard mode and getting back into this state. In short, you can seemingly disable navigation by either removing the keymappings from the Input Manager, or define some new entry in Input Manager (I called it 'None') and set it up so it has no key mappings.

    Then, on your GameObject with EventSystem, you can set the Horizontal and Vertical Axis to "None". Note that you can't just set them to blank, else there will be an error about this not being defined in the Input Manager.

    --edit--
    Or, even better it appears there is a "Send Navigation events" check on the EventSystem, that can be unselected. Doh!

    Do this, and keyboard input mode won't bother your UI as you play your game and use the keyboard. At least this seems to be the case.

    Note that you would think that just setting Navigation to None on buttons would at least fix the issue with buttons. But I've noted that if you are currently mouse over a button and then press a keyboard navigation key, that button will become the selected item in the EventSystem. This doesn't seem right, since the button is tagged as Navigation:None. It also doesn't happen if you aren't mouse over at the time you press a navigation key.

    And for anyone still reading, you can select the GameObject that has your EventSystem class. Then at runtime the inspector will show some useful info including the selected item.
     
  11. Burve

    Burve

    Joined:
    Feb 12, 2011
    Posts:
    139
    Hmm, disable "Send Navigation Events" is an interesting and working option, I don't trust navigation links anyways and what I want to do with navigation I still planed to do manually, so that is good idea to follow.

    edit:
    to be honest using same keys for UI navigation and game navigation at the same time is really bad idea, and so far there is no rule, that say, that you can't have UI with navigation while you need to navigate in game, so, I would say, that main reason for this mess is default setup, where by default UI navigation is set to the same axes as player navigation.
    if, for example, default state sad:
    * use ASWD for player navigation
    * and arrows for UI
    then this issue would not be so popular, but now you do both navigations at the same time and if you don't have problems with UI looking dead while you move around there will be problems at some point when UI will start to react to player movement and highlight something (if Unity do implement highlight state for buttons)
     
    Last edited: Nov 19, 2014
  12. ZY_bros

    ZY_bros

    Joined:
    Feb 25, 2022
    Posts:
    5
    Hate Replying to old forums but this was the first result so yeah.
    solution:
    just trigger a mouse click in the first frame ie.
    public void Start()
    {
    OnPointerClick(new PointerEventData(EventSystem.current));
    }