OK so essentially it’s not really a bug - just the way events work.
UI objects in the menu have Button interfaces attached to them that are activated through OnClick methods.
The problem is, I only want them to be activated when I click them using LMB, but they also react to hitting enter for example.
This is a problem, first, I don’t want that to happen.
Second, some UI objects are ‘selected’ somehow, and when I type the text in a textbox, for example, and then hit Enter, a (seemingly) random UI object gets clicked, when it totally shouldn’t.
Is there a legitimate workaround? I tried using
EventSystem.current.SetSelectedGameObject(null);
but it doesn’t resolve the issue at all.
What are other options?
Probably just unassign the Enter action in the input module associated with your Event System component.
what I mean is, here’s some ui object with a button (attached). When I hit enter using an entirely different ui object (for example a text box after entering sm text), this object is activated too. Or, I hit this object by clicking LMB (as I intend), but if I hit enter (either of two), after that, it is clicked again (which I do not intend).
So I think it is something to do with how Unity editor ‘selects’ objects by default. I do use
EventSystem.current.SetSelectedGameObject(null);
but it didn’t really work
You can see what game object is still focused in the EventSystem component. It just sounds like the button has still been focused whenever you’re hitting enter.
If you don’t want the button to be selectable in certain contexts, then you should disable it.
yeah well there’s a tonne of buttons in just one menu, disabling all of them is quite some work.
I see the selected object in the event system. So I thought, the real problem is when the textbox is selected for editing the text. So I added the line from above (EventSystem.current.SetSelectedGameObject(null)) to the method that is activated by clicking the textbox (open for editing). And it did the job, the Selected object below disappers. I can add it to all other methods, but this was the important one.
What I don’t understand is why Unity doesn’t deselect it by default, because obviously it can lead to unwanted and counterintuitive behavior.
I mean it shouldn’t be ‘deselected’, the focus should change to the text field as both InputField and the TMPro text fields are Selectable.
Also you should probably read that big red error telling you to change to the correct input module for the new Input System.
ah, I see it now! For some reason when I use WSAD, typing the text in the textbox, it starts switching between the ui objects! Is this the expected behavior?
The answer is staring you right in the face with your screenshots! If you have WASD set up for Horizontal or Vertical inputs used in the input module, then it will also used for your navigation.
Again, read the big error message as well. You should upgrade the input module to the one used by the new Input System.
I updated the input system, but still don’t see the wasd setting. Where is it?
Because there no “WASD Setting”. It depends on the inputs set up each of these input actions. Namely the ‘Move’ action handles Navigation. So go to that input action and remove the WASD bindings for it.
ahhh, sorted! It’s nothing to do with WASD setting, or such setting doesn’t exist, and I don’t understand what you mean by ‘Move’ action handles Navigation’. I had to check ‘None’ in Navigation on each button. That did the trick. Still would be great to have this setting for all buttons in the project.
Christ its not that hard. Again it’s staring you in the face in your own screenshots.
If you go to the input action for navigate you’ll see its set up for WASD:
Naturally the DefaultInputActions used by the input module lives in a package, so its not editable. But you can make your own action map and set up the inputs for UI the way you want it to work.
No need to be patronizing, if you know your way around it so well, you could have just said so straight away. So how do I disable it? I deleted the wasd input in UI, but it keeps working for some reason.
Did you edit the DefaultInputActions in the package? Like I said, assets in packages can’t be edited. You need to make your own instance in your project assets.
Can’t or shouldn’t? I deleted the WASD for UI, and it doesn’t work, as expected.
Still can’t find the enter/keypad enter, as it keeps working for some reason
Are you ignoring the warning logging in your console?
Your changes won’t be doing anything. And they’ll just reset at some point.
That’s handled by the Submit action.
The simple solution is to make your own Input Actions and set it up how you want specific to your project.
And then maybe brush up on how to use the New Input System.
Yep, you’re right, the functionality is back. Although the error messages are different. So what should I do then? I guess I can disable the selection using the method above, but that’s kinda boring.
Then do this part first:
I’m not going to teach you how to use the New Input System. All the information for that already exists.