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. Dismiss Notice

How to use IPointerUpHandler

Discussion in 'Scripting' started by D3ftp, Mar 22, 2015.

  1. D3ftp

    D3ftp

    Joined:
    Mar 11, 2015
    Posts:
    8
    Hello guys i have little problem with IPointerUpHandler Interface. i have added this script to my gameobject and Raycaster to my game camera. But i really dont know why it isnt working.

    Code (CSharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using UnityEngine.EventSystems;
    5.  
    6. public class IEventTest: MonoBehaviour, IPointerUpHandler
    7. {
    8.  
    9.     public void OnPointerUp(PointerEventData eventData)
    10.     {
    11.         Debug.Log("Button " + eventData.pointerId + " up");
    12.     }
    13. }
    14.  
     
  2. peXed

    peXed

    Joined:
    Oct 7, 2013
    Posts:
    3
    Hello!

    Hope it is not to late. I had exactly the same problem. I don't know why it is not working. Just use IPointerClickHandler and its interface OnPointerClick.

    It reacts to the release/up event, so I guess it is the same as the PointerUp event.
     
    Sneirox likes this.
  3. psyydack

    psyydack

    Joined:
    Aug 30, 2013
    Posts:
    93
  4. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Do you have an appropriate collider on the game object this script is attached to?
     
  5. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    Would need some more details about your situation, a few queries:
    • Do you have an "event system" in the scene (required for all UI style events)
    • Put another Debug.Log message in without using the pointer data, to see if the event is firing. If the eventdata is null your Debug message wouldn't appear.
    • What are you attaching this script to? A UI component or other 3D object?
    • If it's a 3D object, have you attached the Physics raycaster to your camera?
    Basically need more details about your scene to answer.

    (p.s @BoredMormon the UI events don't use collides :D, just raycasting)
     
    Hyoza likes this.
  6. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    Depends. If you are using a physics ray caster attached to the camera you need the appropriate colliders. If you are using a graphics ray caster attached to a canvas you don't need colliders.

    The rest of your post is spot on.
     
  7. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,683
    That is a fair point! :D Thanks for that.
     
  8. MightyBox

    MightyBox

    Joined:
    Aug 28, 2012
    Posts:
    8
    Well, I've just started to use the EventSystem, and I had a similar problem. When I implemented the IPointerClickHandler interface, everything worked well. When I implement IPointerUpHandler or IPointerDownHandler on their own, they simply don't work!! When I implement both IPointerUpHandler AND IPointerDownHandler, they both work fine! looks like a Unity bug to me - why have separate interfaces if both have to be implemented for them to work?
    We should just have the IPointerClickHandler which requires OnPointerUp, OnPointerDown and OnPointerClick implementations (left empty if not needed).
     
    Novack likes this.
  9. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    That's weird. Went to Unity to check.

    Looks like IPointerDown works on its own. It appears IPointerUp needs something to detect the pointer down event first.

    According to the docs this might actually be intended behaviour.

    Looks like you can implement IPointerDown or write your own EventSystem
     
  10. astechnolabs

    astechnolabs

    Joined:
    Jul 11, 2021
    Posts:
    20
    i have little bit same issue pointerdown calls but pointerup no call on clicking.. anyone have solution?
     
  11. unity_6C82258DF4F967069335

    unity_6C82258DF4F967069335

    Joined:
    Sep 23, 2022
    Posts:
    11
    how can I implement the functionality of shop system like in clash of clans into unity project
     
  12. diegobrego

    diegobrego

    Joined:
    May 28, 2018
    Posts:
    1
    Novack likes this.