Search Unity

Seriously, no support for right click for OnPointerClick?

Discussion in 'UGUI & TextMesh Pro' started by Metricton, Aug 23, 2014.

  1. Metricton

    Metricton

    Joined:
    Jan 3, 2013
    Posts:
    13
    What the heck? Why is there no support for right click on the OnPointerClick? It just ignores all right clicks and only accepts left clicks. Why would you leave out something so simple, and especially considering gamepads could have multiple buttons that you might want to interact with it. For instance, an item I want to right click to do one thing, and left click to do another. Or even, on a gamepad have O do one thing and X do another for the same item.

    I can't use Input.GetMouseButton because OnPointerClick is called after the mouse button has already been released, plus OnPointerClick is never called for right click!!!
     
    Melang, rakkarage and santi8ago8 like this.
  2. superpig

    superpig

    Drink more water! Unity Technologies

    Joined:
    Jan 16, 2011
    Posts:
    4,660
    Huh. Would you believe, I don't think anyone ever brought this up during the beta?

    It looks like it might be possible to support this by adding a custom InputModule, but not very cleanly.
     
  3. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    We will fix this ASAP, can you please log a bug so we can track it?
     
    Togis likes this.
  4. atla

    atla

    Joined:
    Aug 23, 2014
    Posts:
    1
    Hi guys,

    not sure if i have overlooked something. But i started like 2 weeks ago with a new game, initially used NGUI and now happily switched to the 4.6 UI which is pretty damn good.

    Until today where i stumbled upon states of a button. How do i check if a button is KEPT being pressed? I want an event that either gives me up/down or a state that i can check for in Update(). Because i have a FastForward Button in the game and it is supposed to run as long as the user holds it. Did i miss something or is this just not possible right now?

    Please also let me know where i can create the ticket if this is a bug!

    br,
    Marcus
     
  5. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,038
    Add an EventTrigger component and check for PointerDown. Set a flag for the state there. Remove the state in a PointerUp event method. How you want to apply the functionality of it being pressed depends on your implementation, of course :)
     
  6. Metricton

    Metricton

    Joined:
    Jan 3, 2013
    Posts:
    13
    Okay, I filed a bug report using the Unity Bug Reporter on my Mac. I would also just like to note that this problem also applies to OnPointerUp and OnPointerDown as well not detecting anything but the primary button such as left click. They also ignore any other button on the mouse or gamepad.
     
  7. douglasg14b

    douglasg14b

    Joined:
    Oct 2, 2014
    Posts:
    34
    Whats the status on this, has this changed?
     
  8. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,038
    The PointerEventData passed to the different methods now has an attribute for the button clicked, pointerId. It's -1 for the left mouse button, -2 for right and so on.
     
    fieldrequired likes this.
  9. douglasg14b

    douglasg14b

    Joined:
    Oct 2, 2014
    Posts:
    34
    Thanks Orb, is that functionality available for the UI Button?
     
  10. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,038
    Yep, as long as you write a custom script with the event method.
     
  11. douglasg14b

    douglasg14b

    Joined:
    Oct 2, 2014
    Posts:
    34
    I apologize if I'm asking too much of you, when you say write a custom script with the event method. do you mean doing my own raycast on a rightclick and making that determination of what was hit. Or modifying the functionality of the UI Button so that it reacts in a similar manner to a right as well as left click (animation or colors when clicked, calls methods you may have specified in Onclick() in the inspector...etc).

    If it's the later, I am not quite sure how to go about that, would you be able to point me in the right direction?

    Edit: Oh, I'm running 4.6.0, I might want to try updating to 4.6.3 first.
     
  12. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,038
    Nothing so complicated :)

    Example:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.EventSystems;
    3.  
    4. public class Clicky : MonoBehaviour, IPointerUpHandler
    5. {
    6.     public void OnPointerUp(PointerEventData data)
    7.     {
    8.         Debug.Log("Button "+data.pointerId+" up");
    9.     }
    10. }
    11.  
    Add IPointerDownHandler and OnPointerDown, or IPointerClickHandler and OnPointerClick as needed. Check that data.pointerId to select which button is pushed (or which finger, in the case of touch).
     
  13. douglasg14b

    douglasg14b

    Joined:
    Oct 2, 2014
    Posts:
    34
    Oh I see, it appears to automatically adds it in for you. I was trying to find out how to add my methods to the invocation list of w/e delegate unity has behind the scenes for the longest time. I also had to update to 4.6.3, which seems to have changed a few things.
     
  14. orb

    orb

    Joined:
    Nov 24, 2010
    Posts:
    3,038
    I don't think the triggers in the editor GUI have been updated to send to different routes based on which button you press. And yes, the GUI still seems like a beta :)
     
  15. LittleRainGames

    LittleRainGames

    Joined:
    Apr 7, 2016
    Posts:
    97
    This still isn't fixed. It works with OnDrag, and OnBeginDrag, but not OnPointerClick.
     
  16. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    What version of Unity are you using, because it works just fine for me.

    Code (CSharp):
    1.     public void OnPointerClick(PointerEventData eventData)
    2.     {
    3.         if (eventData.button == PointerEventData.InputButton.Left)
    4.         {
    5.  
    This is the start of my method so I limit the response to left clicks only.
     
    vollukas and LittleRainGames like this.
  17. LittleRainGames

    LittleRainGames

    Joined:
    Apr 7, 2016
    Posts:
    97
    Hah funny, I was looking for something exactly like that, I don't know how I missed it. I ended up using OnpointerDown, but this is much better. How embarrassing.