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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Button unselected by mouse movement

Discussion in 'UGUI & TextMesh Pro' started by JFR, Sep 25, 2014.

  1. JFR

    JFR

    Joined:
    Feb 21, 2014
    Posts:
    65
    Hiya guys, I am implementing a text window popping up, with a default button selected in an FPS game. This works, but as soon as the player moves the mouse to look around the scene a bit it becomes unselected. I would expect the unselection only to happen when another button is hovered over?

    Am I missing something, or is the button unlection by mouse movement only normal behaviour?
    Thx
    - JF
     
  2. Capn_Andy

    Capn_Andy

    Joined:
    Nov 20, 2013
    Posts:
    80
    I'm seeing the same behaviour - Even if there is a single button on the screen, the size of the entire screen, if you jiggle the mouse then hit Spacebar (my selection keystroke on keyboard) it doesn't register, I have to hit an arrow key first to "re-select" the item with the keyboard.
     
  3. JFR

    JFR

    Joined:
    Feb 21, 2014
    Posts:
    65
    Glad to hear I'm not the only one.

    The strange this is (I aminstantiating the window from a prefab), about one out of 3 times the selection will stick, other times it won't. I haven't been able to find the cause as of yet, and it's really hard to debug since I don't have access to the button code itself. Is this a bug?
     
  4. comixplay

    comixplay

    Joined:
    Sep 27, 2013
    Posts:
    104
    It happens to me too, and it's really frustrating,
    As a "workaround" ... I'm using Images instead of Buttons...
     
  5. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,184
    This is currently intentional, we switch from keyboard input to mouse input when we detect the mouse has been moved.

    If you want to change this grab a copy of the StandaloneInputModule and modify the function:
    Code (csharp):
    1.  
    2.         private bool UseMouse(bool pressed, bool released, PointerEventData pointerData)
    3.         {
    4.             if (m_CurrentInputMode == InputMode.Mouse)
    5.                 return true;
    6.  
    7.             // On mouse action switch back to mouse control scheme
    8.             if (pressed || released || pointerData.IsPointerMoving () || pointerData.IsScrolling ())
    9.             {
    10.                 m_CurrentInputMode = InputMode.Mouse;
    11.                 eventSystem.SetSelectedGameObject (null);
    12.             }
    13.  
    14.             return m_CurrentInputMode == InputMode.Mouse;
    15.         }
    16.  
    If you look at the code it enables mouse if you press or release the button or move / scroll. You can change this to only 'enable' the mouse if the mouse is over a different object than the selected object.
     
  6. JFR

    JFR

    Joined:
    Feb 21, 2014
    Posts:
    65
    Thanks for the reply Tim. I will give the solution a go.
     
  7. jcman

    jcman

    Joined:
    Jan 12, 2014
    Posts:
    15
    I would also like to modify the InputModule - I would like to receive input from multiple controllers and drive focus separately for each player on a player join/setup screen.

    Tim C - Where do I find the source to StandaloneInputModule that you mentioned?

    Thanks!
     
  8. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,184
  9. jcman

    jcman

    Joined:
    Jan 12, 2014
    Posts:
    15
    Great, thanks Tim.