Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
7
Question by valentin-simian · Oct 06, 2015 at 01:37 AM · clickeventsystemphysics.raycastclickable

Implementing IPointerClickHandler interface does not seem to work

Hello,

I am using EventSystems to register a click on a Game Object using the following:

 using UnityEngine;
 using UnityEngine.EventSystems;

 public class ClickChecker : MonoBehaviour, IPointerClickHandler {
    public void OnPointerClick (PointerEventData eventData)
    {
        Debug.Log ("clicked");
    }
 }

It should be noted that the methods in the IPointerEnterHandler and IPointerExitHandler are invoked, and I am getting the correct PointerEventData, but the method within the IPointerClickHandler interface, OnPointerClick, is not invoked.

(I have a Physics Raycaster attached to my camera, so this is not the culprit).

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Kiwasi · Oct 06, 2015 at 05:06 AM 0
Share

Does your object with this script on have an appropriate 3D collider? You also need an EventSystem object in your scene.

avatar image valentin-simian Kiwasi · Oct 06, 2015 at 05:24 AM 0
Share

Yes, it's just a Box with a Box Collider. And an Event System is in place.

avatar image valentin-simian Kiwasi · Oct 06, 2015 at 07:31 PM 0
Share

Update: recreated from a scratch project, the method is now invoked. Not sure what's the cause, will update again if / when I know.

avatar image JoshuaMcKenzie · Nov 20, 2015 at 05:39 AM 1
Share

I can't say this is a true answer, only a guess.

Its possible that everything is set up correctly but the click event is getting passed to a different object (whether that object is listening for that event or not). a good way to test what your actually clicking on is to select the Eventsystem and expand its info on the inspector (you need to drag up the bar thats usually on the bottom of the Inspector panel). while in-game when you click on something the EventSystem will populate this info and tell you what the pointer is over at the time.

7 Replies

· Add your reply
  • Sort: 
avatar image
33
Best Answer

Answer by roddles · Sep 19, 2017 at 05:30 AM

IPointerClickHandler Not Working Checklist


  1. Added EventSystem game object to scene (Create -> UI -> Event System)

  2. Camera has a Physics Raycaster (Select Main Camera, Add Component -> Event -> Physics Raycaster)

  3. Selectable object is a MonoBehavior-derived class that implements IPointerClickHandler, IPointerDownHandler, and IPointerUpHandler (see accepted answer).

  4. Selectable game object includes selectable object MonoBehavior script.

  5. Selectable game object includes a collider (box, mesh, or any other collider type).

  6. Check Raycaster Event Mask vs. game object's Layer mask

  7. Verify no collider (possibly without a mesh) is obscuring the selectable game object.

  8. If collider is a trigger, verify that Queries Hit Triggers is enabled in Physics settings.


This list covers all the most common issues (Adding this list for posterity as this problem continues to trip me up every time I start a new project).

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DragonBloodGames · Oct 14, 2019 at 02:36 PM 0
Share

There is also a new point on the list, to be checked.

  1. If you upgrade to the new Input System, you need to update the EventSystem GameObject. There is a button in the Inspector of that component, to swap to the new "Input System UI $$anonymous$$odule Script Component".

avatar image
13

Answer by adamonline45 · Nov 19, 2015 at 11:00 PM

I have just run into this. By implementing IPointerUpHandler and IPointerDownHandler with empty methods, the OnPointerDown method was invoked as expected.

 using UnityEngine;
 using UnityEngine.EventSystems;
 
 public class MyClickableBehaviour : MonoBehaviour, IPointerClickHandler, IPointerDownHandler, IPointerUpHandler
 {
     public void OnPointerDown( PointerEventData eventData )
     {
     }
 
     public void OnPointerUp( PointerEventData eventData )
     {
     }
 
     public void OnPointerClick( PointerEventData eventData )
     {
         Debug.Log( "Clicked!" );
     }
 }
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image CouldNotThinkOfOneSorry · Jul 29, 2016 at 08:19 AM 0
Share

I too had this issue, and your solution solved it.

987456149865496856468531685340 / 10 => would definitely recommend.

Is this because the OnPointerClick event needs a corresponding "Down" and "Up" event before a "Click" is registered?

avatar image Harinezumi · Feb 02, 2017 at 12:45 PM 0
Share

I also wonder why OnPointerUp() and OnPointerDown() have to be implemented (even if empty)... shouldn't OnPointerClick() work anyway?

avatar image beyonddoor · Jan 07, 2021 at 11:13 AM 0
Share

solve my problem

avatar image
6

Answer by Fimgers · Oct 22, 2016 at 06:27 PM

I had this issue as well what I had to do was add a Physics Raycaster script to my camera via the add component and searching "Physics Raycaster " every thing worked after that.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image jbnunn · Dec 05, 2021 at 02:45 PM 0
Share

This still works in Unity 2020.2.15. Note that you don't need the OnPointerUp or OnPointerDown methods with this answer.

avatar image
0

Answer by obstinate · Aug 14, 2017 at 10:08 AM

If your component is inside a canvas, another solution is to add a Graphic Raycaster component on the component to be clicked.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by WigglingPotatoDev · Sep 14, 2017 at 06:31 AM

Add a collider to your game object.

I was stuck on this as well. I had a Physics 2D Raycaster component attached to my main camera, and an EventSystem added to my scene.

My game object implemented the pointer handler interfaces, but what was missing for me was the (Box) Collider. Once I added that to my game object then pointer event handlers were working.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
  • 1
  • 2
  • ›

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

48 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make an object respond to a click in c# only when a variable equals a certain value 1 Answer

event triggered by the wrong camera 0 Answers

Button OnClick() seemingly not triggering on Mac 0 Answers

Button is not being clicked. 1 Answer

Use Event Triggers or something similar on non-UI objects? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges