Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Nov 01, 2017 at 08:45 PM by Ianamus for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Ianamus · Nov 01, 2017 at 01:41 AM · eventeventsystemuser interfaceevent triggering

Issues implementing UI event triggers via script

I have been trying to add Event triggers to my UI elements via script and get them to work. But the events just never fire or do anything, and I can't find any answers as to what could be causing the issue. Here is the code used to add the event:


 EventTrigger trigger = abilityIcon.AddComponent<EventTrigger>();
 EventTrigger.Entry entry = new EventTrigger.Entry();
 entry.eventID = EventTriggerType.PointerEnter;
 
 entry.callback.AddListener((eventData) =>
 {
     Debug.Log("Event!");
 });
 
 trigger.triggers.Add(entry);


And here is an image of the UI element in my editor after running the game:


alt text


I've tried deleting every other UI element except for the one with the event trigger so that I know nothing is blocking it. But the function never seems to fire under any event type.

If anybody has any ideas about what could be causing the issues I'd really appreciate it!


event-trigger-issue.jpg (222.3 kB)
Comment
Add comment · Show 2
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 Glurth · Nov 01, 2017 at 06:05 PM 1
Share

Confirm your Canvas has a GraphicRaycaster component, and if so, double check it's settings. If not, that's probably your issue; just add one.

avatar image Ianamus Glurth · Nov 01, 2017 at 08:45 PM 0
Share

Thanks, it was a combination of this and the icon being blocked by another UI object in the canvas. It's working now.

1 Reply

  • Sort: 
avatar image
0

Answer by jeango · Nov 01, 2017 at 05:23 PM

in my experience, listeners that are added via code are not visible in the inspector when the game is running.

Comment
Add comment · Show 2 · 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 Ianamus · Nov 01, 2017 at 05:27 PM 0
Share

I have read that they will not appear in the inspector, but the issue is not simply that they aren't appearing in the inspector, they aren't firing either.

$$anonymous$$oving the cursor over the button does not print a debug log message. I've never been able to get any of the event triggers I've added via script to do anything at all.

avatar image jeango · Nov 01, 2017 at 08:26 PM 0
Share

what I meant to say is that there’s nothing wrong with your code, so the issue is not about the registration of the listener but rather that the event just never happens. I think what Glurth is saying makes sense. You should investigate the reasons why the event doesn’t occur

Follow this Question

Answers Answers and Comments

74 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 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

Hide/show UI Button and trigger the OnPointerDown event ?! 0 Answers

How to drag gameobjects (other than ui elements) using the event trigger? 2 Answers

Can't fire a Custom Event on UI Button Touch OnClick 1 Answer

Event trigger i put on an empty game Object isn't responding even though i have an Event System and everything ,Unity Event trigger isn't responding to clicks 1 Answer

Correct way to send an event to a specific enemy 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