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 /
avatar image
0
Question by CrowbarSka · Feb 06, 2019 at 02:34 PM · uiinputeventsystemeventsevent handlers

How do I detect when UI events are triggered on *any object*?

I want to know when UI events are being triggered so I can intercept them and inject my own code.

To do this, I planned to add my own script to the object that has the EventSystem and StandaloneInputModule components, and that would use EventTriggers. However, I didn't realise that EventTriggers need to be attached to the actual object that's being manipulated (i.e. on each and every button in the canvas).

Instead, I want to add a 'global detection system' that tracks whenever navigation directions are pressed or any button is clicked, with "Submit" or "Cancel", then fire off some events as I need to.

Thanks!

Comment
Add comment
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 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by xxmariofer · Feb 06, 2019 at 03:09 PM

why you need to do this? isnt easier to create custom buttons that fire your methods? i mean if you need to inject your own code this is the easier solution. something like

  button.onClick.AddListener(() => ButtonClicked());

and create a method called ButtonClicked with all the code you want, you just need to add that listener to each button you want.

Comment
Add comment · Show 5 · 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 CrowbarSka · Feb 06, 2019 at 03:14 PM 0
Share

To add some context, I'm trying to create a workaround for the problem I detailed here: https://forum.unity.com/threads/ui-navigation-breaks-if-you-deselect-all-objects-with-mouse-or-touch.624679/

Essentially the problem is: if you mouse click or touch in empty space, all buttons become deselected and you can't re-select them using keyboard/controller alone (you have to continue using mouse/touch).

The buttons all work fine individually, and navigation is fine until you change input method. If the player accidentally clicks or touches without realising it, the entire UI system effectively breaks for them. I observed a play-tester do this and they thought the game had crashed.

I'm trying to add some code that will detect that the player is trying to continue using keyboard/controller when nothing is highlighted, and then subsequently re-highlight the last highlighted object.

avatar image xxmariofer CrowbarSka · Feb 06, 2019 at 03:48 PM 0
Share

ok sorry i missunderstood you. you want that when the player clicks the button, it gets highlited again, but not fired right? the only thing i can think of is adding a script to each button, implementing a the onselect method https://docs.unity3d.com/ScriptReference/UI.Selectable.OnSelect.html storing a reference to the last selectable ui button in a uimanager, and once you detect the player trys to use the inputs again use the https://docs.unity3d.com/ScriptReference/UI.Selectable.Select.html to select the reference to the last selected object. i have never done this so i am not sure if this would work, and each object having that script is the only way i can think of for getting the selected/deselected events altough feels bad for performance.

avatar image CrowbarSka xxmariofer · Feb 06, 2019 at 03:54 PM 0
Share

No worries!

Yes that's what I'm trying to do. The part I'm struggling with is where you said "once you detect the player trys to use the inputs again". Presumably StandaloneInput$$anonymous$$odule is still listening for these events, but how can I tap into them?

I'm writing a horrible simple hacky fix using the basic Input manager class, but it feels like there should be a more integrated way.

Show more comments

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

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

UI: Mouse events not working 1 Answer

Can I Simulate the "Submit" Event with Gamepad Buttons? 0 Answers

Unity 2019.3 any way to make mouse events pass thru an UI element without disabling "Raycast Target" ? 2 Answers

Setting up EventTrigger programmatically for GameObject throws NullReferenceException 0 Answers

EventSystem - detect any click NOT on object 1 Answer


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