Maybe laggs? Where there any fps drops? And for which plattform do you use this?
I remember I had a similar problem on Android, and fixed it (if I remember corectly) in my GUI. I disabled the receive reycast option on all not needed BoxViews and other UI elements. Hope this helps you.
Happens in the editor. Unfortunately, every UI elements that shouldn’t receive raycasts are already set up as such. It seems to be running at a constant 80 fps.
Is your mouse over the same object when you release the mouse?
If you click over Object One, then release over Object 2 OnPointerUp will not fire (for either of them)
It does in my case, as long as pointer down was called over the object on which the script is attached to.
Unless I’m misunderstanding you guys. If pointerdown is called on object A, you can mouseover any other object, the event system will confirm that you’re over a different object but onpointerup will still fire for the object A when you release.
I don’t believe it’s supposed to work that way (but of course the documentation is non-existent). Can you confirm the behavior by creating a simple scene with two cubes that do not overlap in any way?
Created a blank scene, added a canvas and 2 UI images. They’re not overlapping in any kind of way. One is called A, the other B. When pointer down is called on A, no matter where the pointer is when it’s released, pointerup is always called on A as well.
using UnityEngine;
using UnityEngine.EventSystems;
public class rgergreg : MonoBehaviour, IPointerDownHandler, IPointerUpHandler {
public void OnPointerDown (PointerEventData eventData) {
Debug.Log ("Down called on object :" + gameObject.name);
}
public void OnPointerUp (PointerEventData eventData) {
Debug.Log ("Up is called on object :" + gameObject.name);
}
}
Ok that sounded weird so I did some testing and your right. I made 2 buttons called ButtonOne and ButtonTwo, and added this script:
public class GenericTest : MonoBehaviour, IPointerDownHandler, IPointerUpHandler {
public void OnPointerDown(PointerEventData eventData)
{
Debug.Log("You pressed down on " + gameObject.name);
}
public void OnPointerUp(PointerEventData eventData)
{
Debug.Log("You released on " + gameObject.name);
}
}
And whenever I clicked Button One, I would get:
“Your pressed down on Button One”
and no matter where I released I would get:
“You released on Button One”
Which is not how I expected it to work.
EDIT: I forgot to say I added it to the OnClick handler
Now I added this code and hooked up the Button’s OnClick to it:
public void Pressed()
{
Debug.Log("You Pressed Button One");
}
And it does work as I expected. If you push down and release over Button One this function gets called. IF you push down and move off of Button One this function does not get called.
So what are you doing when you don’t get your Pointer Up Calls? I couldn’t ever make it so the Pointer Up didn’t get called in my simple example. I can’t imagine this happening on a PC build… but maybe on a IPhone or android. I have no idea on touches.
Not the exact same problem, but a trivia for those struggling with related cases, maybe:
I’ve been troubled because OnPointerUp does not get called unless OnPointerDown was called for the same object previously.
So Objects A and B
Pointer down on A => OnPointerDown A
Move cursor off A, over B
Pointer up on B => OnPointerUp A (as stated above, this always fires for the object that had registered the OnPointerDown)
My problem is that I found no way to detect a single “pointer up” on object B for specifically the cases where the pointer had started (OnPointerDown A) anywhere else than over object B.
If you were in the position to really want a pointer up over an object you could always work it out.
Maybe with Input.GetMouseButtonUp or something and checking if the pointer is over the game object, or if on the UI, if the recttransform contains the position, for example. Or even you could have IPointerEnter on a game object … a few options, I think they’d work
I think the OnPointerUp is called only if the PointerEventData.pointerPress is set the this.gameObject. So what you can do is to set it somewhere like in the OnPointerEnter.
using UnityEngine;
using UnityEngine.EventSystems;
public class UIPointerUpHandler : MonoBehaviour, IPointerUpHandler, IPointerEnterHandler, IPointerExitHandler
{
public void OnPointerUp (PointerEventData eventData)
{
print ("PointerUp event was fired");
}
public void OnPointerEnter (PointerEventData eventData)
{
eventData.pointerPress = this.gameObject;
}
public void OnPointerExit (PointerEventData eventData)
{
eventData.pointerPress = null;
}
}