Search Unity

PointerExit being called by "Positive/Negative Button" input?

Discussion in 'Unity UI (uGUI) & TextMesh Pro' started by Doghelmer, Oct 29, 2014.

  1. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    112
    Using the new GUI system, I'm using PointerEnter to display a tooltip when the user hovers the mouse over an inventory item. This works fine until I press one of my buttons to move the character (ASDW), and the tooltip disappears. After a lot of inspection, I figured out that pressing the "Negative Button" and "Positive Button" input commands are causing PointerExit to fire.

    I don't want to jump the gun, but this seems like a potential bug to me-- I haven't been able to find an explanation other than "Negative Button / Positive Button causes PointerExit". Has this happened to anyone else? What would be a decent workaround?
     
    rakkarage likes this.
  2. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    790
    Same thing here.
    PointerExit fires when pressing keys, but that doesn't make any sense!
    The mouse cursor stays in the UI element but the event is still fired.
    I hope someone can at least offer a workaround for that. It's really breaking my game.
     
    rakkarage likes this.
  3. Doghelmer

    Doghelmer

    Joined:
    Aug 30, 2014
    Posts:
    112
    Have you tried the new version 4.6.1 released a couple of weeks ago? The issue appears to be fixed, at least as far as I can tell.
     
  4. progrematico

    progrematico

    Joined:
    Dec 10, 2014
    Posts:
    9
    I'm on the latest version of Unity and I'm having the same issue. I have an inventory system that "highlights" an inventory slot when you mouse over it. This is done using the PointerEnter/Exit events. As soon as I move my character though, these events stop firing altogether. There is a way to get them firing again as I explain below.

    Canvas
    ->Inventory (Image)
    ->ItemSlot0.0 (Image)
    ->ItemSlot1.0 (Image)
    ->...

    Inventory has an Event Trigger attached to it that handles the dragging (Drag and BeginDrag)
    ItemSlotx.x has an Event Trigger attached to it that handles the highlighting (PointerEnter, PointerExit)

    On PointerEnter, the texture of the ItemSlot image is changed to a highlighted one. On PointerExit, it is changed back to the normal one.
    This works perfectly until I move my character. As soon as I do that, the PointerEnter/Exit events stop getting triggered altogether.
    I can get them triggering again and working back to normal by Dragging my Inventory somewhere. Simply dragging it is enough to get the events firing again.

    I'm not sure if it is easy to see what I'm trying to say, so here's a gif of the issue
     
  5. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    I had this issue (it was in 4.6 Beta 20). I'm doing the same thing as you're doing but for my spells' description. If I remember well, you shouldn't use the inspector to do that but use directly OnPointerExit function inside a script.

    I'm not sure at 100%, let me check that tonight, when I come back home.
     
  6. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    2,900
    My guess it that the focus is lost if you navigate the gui with the Horizontal / Vertical input axis.
    You should be able to change it on the EventSystem GamObject -> Standalone input Module. Just remove Horizontal / Vertical input axis and unity should no longer try to navigate the gui with the keyboard / gamepad
     
  7. dadude123

    dadude123

    Joined:
    Feb 26, 2014
    Posts:
    790
    That would make sense if the events were related to the focus.
    But this is just about PointerEnter/Exit. So just the mouse cursor.
    And obviously the mouse cursor does not move when you press a WASD, so the PointerExit event should not fire.
     
  8. fffMalzbier

    fffMalzbier

    Joined:
    Jun 14, 2011
    Posts:
    2,900
    Another case of good idea gone wrong. This should get fixed. Can you make a bug-report with a simple example and post the case number here?
     
  9. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    This is not a bug, I had it and once I found the solution, it sounded normal.

    Again, I don't currently have access to my code.
     
  10. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    Everything works well on my game (okay, this is a screenshot, but I can move and my description will still be there)

    unitydescription.jpg

    Show me your project hierarchy (as I did) and the functions you call when the mouse enters and exits.
     
  11. progrematico

    progrematico

    Joined:
    Dec 10, 2014
    Posts:
    9
    Glad to see you found a solution. I'm at work and don't have access to my project right now, but I will post some images tonight to show you what I'm doing.
     
  12. progrematico

    progrematico

    Joined:
    Dec 10, 2014
    Posts:
    9
    So I'm just finishing up at work but I was able to recreate the issue in a brand new Unity project. Here's the breakdown:

    Screen Shot 2014-12-10 at 5.14.36 PM.png
    This is the game scene. The gray cube is just a cube that I move with the A and D as you will see in a script below.
    The Light Gray panel is the "inventory". It is draggable - you will see this below as well.
    The Blue panels are the "inventory slots". They have the pointer enter/exit events as you will, again, see below.

    Here's the hierarchy:
    Screen Shot 2014-12-10 at 5.14.41 PM.png
    As you can see, the inventory panel is the one that is highlighted. The next three panels are the inventory slots that are children of the inventory panel.

    Here is the inspector pointing to the inventory panel:
    Screen Shot 2014-12-10 at 5.14.49 PM.png
    The things to note here are the Draggable script and then Event Triggers that are set up here.

    The inventory slots have these settings:
    Screen Shot 2014-12-10 at 5.15.02 PM.png
    Note the Slot script and the event triggers here.

    Finally, the cube looks like this:
    Screen Shot 2014-12-10 at 5.25.46 PM.png
    Note the InputManager script and the fact that it's a rigidbody (this is how I move the object in my game so I added the rigidbody here as well)

    Okay. That's the Unity setup. Here are the scripts:
    InputManager.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class InputManager : MonoBehaviour {
    5.    
    6.     // Update is called once per frame
    7.     void Update () {
    8.         if (Input.GetKey(KeyCode.D)) {
    9.             rigidbody.MovePosition(rigidbody.position + new Vector3(0.03f, 0, 0));
    10.             //transform.position += new Vector3(0.03f, 0, 0);
    11.         } else if (Input.GetKey(KeyCode.A)) {
    12.             rigidbody.MovePosition(rigidbody.position + new Vector3(-0.03f, 0, 0));
    13.             //transform.position += new Vector3(-0.03f, 0, 0);
    14.         }
    15.     }
    16. }
    17.  
    Yes, I tested both the rigidbody movement and the transform position "teleportation". They both seem to break the event triggers.

    Draggable.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Draggabble : MonoBehaviour {
    5.  
    6.     private Vector3 startPos;
    7.     private Vector3 startMouse;
    8.  
    9.     public void BeginDrag() {
    10.         startPos = GetComponent<RectTransform>().position;
    11.         startMouse = Input.mousePosition;
    12.     }
    13.    
    14.     public void Drag() {
    15.         Vector3 newPos = GetComponent<RectTransform>().position;
    16.         newPos.x = startPos.x + Input.mousePosition.x - startMouse.x;
    17.         newPos.y = startPos.y + Input.mousePosition.y - startMouse.y;
    18.         GetComponent<RectTransform>().position = newPos;
    19.     }
    20. }
    21.  
    Slot.cs
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class Slot : MonoBehaviour {
    6.  
    7.     public void MouseEnter() {
    8.         GetComponent<Image>().color = Color.red;
    9.     }
    10.    
    11.     public void MouseLeave() {
    12.         GetComponent<Image>().color = Color.blue;
    13.     }
    14. }
    15.  
    That's it. That's the whole project. Sorry for the long post, I just wanted to be as transparent as possible. The outcome is the same thing as my earlier gif - it works until I move the cube. As soon as I move it the events stop triggering. Dragging the inventory around causes the triggers to be fired again.

    Very odd. Hopefully your solution applies to this as well!
     
  13. progrematico

    progrematico

    Joined:
    Dec 10, 2014
    Posts:
    9
    Okay, I just figured it out.

    So, I don't know why I didn't test this before, but I just played around with it again and it seems that Dragging isn't what causes it to fire again. It's clicking.

    I got it to stop firing events after I moved the cube, then I simply clicked, and the events started firing again. It doesn't matter where I click in the game, the events start firing again as soon as I click.

    This got me thinking about what @fffMalzbier said. A focus thing. Turns out he was right. All I had to do to fix the issue was go into Edit->Project Settings->Input and change the Horizontal axis. I deleted 'a' and 'd' as alternate positive/negative buttons and tried again. Sure enough, success!

    I'm not sure why the Event Trigger's Standalone Input Module points to the same Horizontal axis as a regular game would - it seems to be for allowing movement within the UI with the same horizontal axis that's used for the game. Seems a little odd to me. It should probably have been a something you can turn on and off with a checkmark but at least I found a solution.

    Thanks to everyone that replied. I hope this thread will help another fellow Unity developer that runs into the same issue!
     
  14. Sbizz

    Sbizz

    Joined:
    Oct 2, 2014
    Posts:
    250
    Oh S*** yes. I just checked my input keys and it appears that I removed the Horizontal and Vertical keys (but I still need them to exist for the EventSystem component).

    Sorry that I didn't check that! I did that 1+ month ago :/

    I don't really know why these inputs have an impact on the mouse events.. this is weird, maybe a bug ? It could be a good idea to report this "bug / weird issue".

    Edit: Oh ok, I got it. The Navigation system uses the Horizontal and Vertical inputs to move from one to another UI element. They should have used the "Tab" key and switch between the elements with that key.
     
  15. progrematico

    progrematico

    Joined:
    Dec 10, 2014
    Posts:
    9
    Hah, no worries. And yes, exactly, using the same inputs that one would use in their game is, I think, silly. I guess you could always have it point to a new Input that just has the positive button set to the Tab key for that functionality.

    I don't need this in my game though, so just getting rid of it will do. Thanks again :)
     
unityunity