Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 Omti1990 · Feb 05, 2021 at 01:47 PM · uiinputbug-perhapsmouseclick

button.Select() and alternatives don't seem to work when called via new input system

Hello,

I've got a weird problem. I've been trying to make a map for my game, which also includes a list of relevant objects on the map that can be clicked (it's all Buttons).

Now the intention is that if you click something on the list it's marked and focussed on the map and if you click something on the map it's marked and selected on the list (for better controller support).

The first part works perfectly fine. Where things get weird is when I click something on the map. For some reason the Button does not get selected. Actually nothing gets selected despite the script being successfully run (put some random button on the UI and tried to select it with GameObject find). Meanwhile when I run the same select script from a UI Button that works perfectly fine.

The only real difference I can find is that when the script doesn't work it's called from the new InputSystem.

 controls.playerControls1.Interact.performed += ctx => mapClick();

While the other time it's triggered directly by the button.

 private void OnEnable() {
             Button.onClick.AddListener(onClick);
         }



I've been using this standard procedure to set the selected button:

 public static void SetSelectedUIElement(GameObject _gameObject)
         {
             UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(null);
             UnityEngine.EventSystems.EventSystem.current.SetSelectedGameObject(_gameObject);
             Debug.LogWarning("Menu: SetSelectedGameObject to: " +_gameObject.name);
         }



I also tried something like button.Select(), but that also fails.

I'm extremely confused why I can't set the SelectedGameObject via my input system, while it works perfectly fine for the button click. It does seem to sort of work, because the button flickers white for a moment, even on the mapClick() even if it doesn't select. (That doesn't happen when I comment out the selection code, so the selection Code seems to be doing something).

Did anyone else ever experience something like this?

Edit: Hm, I've experimented a bit more and it doesn't seem to be the input system per se, it's only when clicked via mouse. So I suspect the script works, but the mouseclick unsets the button immediately afterwards since I clicked somewhere else on the UI, not the selected button. Does anyone know how to deal with this?

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
Best Answer

Answer by Omti1990 · Feb 05, 2021 at 03:11 PM

Okay found the solution for my problem:

I just needed to remove the tick on DeselectOnBackgroundClick in the InputSystem UI Input Module on the EventSystem gameObject in the inspector.

alt text

It works perfectly now...

sorry for the confusion, it really seemed like the code wasn't working and I didn't realize the mouse click was the problem.


inputsystem.jpg (43.2 kB)
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

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

209 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Touch a specific area on the screen 2 Answers

Second Player Cannot Navigate the Menu 2 Answers

Unity sometimes misses Mouse Button Release 1 Answer

Open and close UI Menu on background mouse click 1 Answer

How can I get text in a canvas to display the name of a key that is chosen by the player in the input panel of the launcher? 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