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

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?

1 Like

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.

1 Like

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.

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

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.

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

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.

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?

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.

Everything works well on my game (okay, this is a screenshot, but I can move and my description will still be there)

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

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.

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:

1881364--121010--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:
1881364--121011--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:


The things to note here are the Draggable script and then Event Triggers that are set up here.

The inventory slots have these settings:


Note the Slot script and the event triggers here.

Finally, the cube looks like this:


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

using UnityEngine;
using System.Collections;

public class InputManager : MonoBehaviour {
   
    // Update is called once per frame
    void Update () {
        if (Input.GetKey(KeyCode.D)) {
            rigidbody.MovePosition(rigidbody.position + new Vector3(0.03f, 0, 0));
            //transform.position += new Vector3(0.03f, 0, 0);
        } else if (Input.GetKey(KeyCode.A)) {
            rigidbody.MovePosition(rigidbody.position + new Vector3(-0.03f, 0, 0));
            //transform.position += new Vector3(-0.03f, 0, 0);
        }
    }
}

Yes, I tested both the rigidbody movement and the transform position “teleportation”. They both seem to break the event triggers.

Draggable.cs

using UnityEngine;
using System.Collections;

public class Draggabble : MonoBehaviour {

    private Vector3 startPos;
    private Vector3 startMouse;

    public void BeginDrag() {
        startPos = GetComponent<RectTransform>().position;
        startMouse = Input.mousePosition;
    }
   
    public void Drag() {
        Vector3 newPos = GetComponent<RectTransform>().position;
        newPos.x = startPos.x + Input.mousePosition.x - startMouse.x;
        newPos.y = startPos.y + Input.mousePosition.y - startMouse.y;
        GetComponent<RectTransform>().position = newPos;
    }
}

Slot.cs

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Slot : MonoBehaviour {

    public void MouseEnter() {
        GetComponent<Image>().color = Color.red;
    }
   
    public void MouseLeave() {
        GetComponent<Image>().color = Color.blue;
    }
}

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!

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!

Oh shit 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 :confused:

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.

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 :slight_smile: