Input specific UI navigation (for example only for PAD1)

Hello. I am creating a co-op game in which there are multiple input systems. Unity’s buttons navigation seems nice but it does listen for inputs from all controllers. How do I specify it so that for example Button1 listens only for mouse clicks, Button2 listens only for PAD1? (there are more pads involved)

The bad news is, there is no easy integrated way to do what you’re asking in UI Toolkit. The event system is centralized and all panels listen to only one common input source, as things are right now.

However, the good news is, there should be a way for you to make this work by manually sending the right events to the appropriate elements, relying on some custom input update loop that you’d be managing on your side of things.

Here’s an example of how you could have only button1 receiving clicks and button2 receiving pad1 confirm button presses.

ViualElement uiRoot;
IPanel uiPanel;

void Start()
{
    uiRoot = GetComponent<UIDocument>().rootVisualElement;
    uiPanel = uiRoot.panel;
    uiRoot.RegisterCallback<PointerDownEvent>(OnPointerDown, TrickleDown.TrickleDown);
}

void Update()
{
    // Replace this by code that checks that the focused element belongs to the pad1 player.
    if (Input.GetButton("Pad1Confirm") && uiPanel.focusController.focusedElement?.name == "button2")
    {
        using (var evt = NavigationSubmitEvent.GetPooled())
            uiRoot.SendEvent(evt);
    }
}

void OnPointerDown(PointerDownEvent evt)
{
    // Replace this by code that checks that the focused element belongs to the mouse player.
    if (uiPanel.Pick(evt.position)?.name != "button1")
        evt.StopPropagation();
}
1 Like

Thanks for your reply @uBenoitA , but I have found a better way. I didn’t know about MultiplayerEventSystem which handles this for us.