Unity UI Toolkit + New Input System

Hi,

some months ago i changed to the new Input System.
I like it, because rather then doing “if keyDown is ‘F’ do something” i can instead declare some Action.
Later i can bind this action to whatever key without changing code.

now i changed from UI to UI Toolkit.
This allowes me to RegisterCallbacks to Elements.
But this is again the old way “if keyDown is ‘F’ do something”.

Here is what i have:

And i would like to use this Action, like this:

.RegisterCallback<basicDefaultInput.Player.FocusSelection>(FocusSelection);

But this does not work.
How can i make this work ?
Even if it would be hefty work around.

Any help is welcome!

You probably want this: Unity - Manual: Keyboard events

Or you can provide a central point to register to inputs directly through the Input System.

Though I would just handle this from a monobehaviour honestly, and have inputs puppet the UI.

Thank you spiney199,

after looking more into this i changed my mind. Now i will do this:
The Hard UI throu UI Toolkit will have some RegisterCallback but not too many because those will be unREbindable.
The rest, mainly ingame controlls, will go throu the New Input System.

But out of curiosity, what do you mean with this:

Do you have any Examples or Vids i could check out on this?

Just a central manager that you can read/register all inputs through. Be it a singleton object, static class, whatever. I don’t know any tutorials, it’s something you should be able to do with enough C#/Unity knowledge.

You mean like an InputManager Singleton that does Update( AnyInput → some Action ) ?
But thats currently how it is handled.
I hoped you had something else in mind.

Thank you non the less

What I do is this:

            // == stage navigation

            var btnPrevious = element.Q<Button>("button-prev");
            btnPrevious.clicked += () =>
            {
                previousPanel();
            };
            var btnNext = element.Q<Button>("button-next");
            btnNext.clicked += () =>
            {
                nextPanel();
            };

and this:

            controls.PlayMenu.NextPanel.performed += nextPanel;
            controls.PlayMenu.PreviousPanel.performed += previousPanel;

and:

        private void nextPanel()
        {
...
        }

        private void nextPanel(InputAction.CallbackContext context)
        {
            nextPanel();
        }

I can change the keys anytime and my code won’t change. Look for samyam tutorials on youtube.