How can multiple users control a single UI canvas using InputSystem?

Hi, I am working on a local co-op game where each user uses a different device and controls a different character. The game does not feature split-screen and only makes use of a single UI canvas, which each user should be able to control.

**The issue:**

When the game is launched, the scene only contains the main menu and it can be used by any device. From there, users are able to join and select a device to use. When the game starts, different *PlayerInput* are spawned for each user + device combo.

At this point each device controls its corresponding character just fine, but once the "Pause Menu" is displayed (and the InputActionMaps are switched) only one of the users is able to use the UI.

**My current configuration:**

  • I have a PlayerInputActions named MyActions with two maps: Gameplay, Menu
  • Each character prefab contains a PlayerInput that uses MyActions
  • The UI has a EventSystem and InputSystemUIInputModule that uses MyActions/Menu

**What I have already tried:**

  • Replace the UI EventSystem for a MultiplayerEventSystem, didn’t work
  • Replace the UI EventSystem for a MultiplayerEventSystem and add new MultiplayerEventSystem and InputSystemUIInputModule to each character that spawns, didn’t work
  • All of the above plus pointing the PlayerRoot field of each MultiplayerEventSystem to the UI and pointing the UI Module field of each PlayerInput to its corresponding module, didn’t work
  • Exactly the same but pointing the UI Module field of each PlayerInput to the module on the UI, didn’t work

I ran out of ideas already, I can not find any help in either the docs or the forums. Has anyone faced a similar issue? Could you please explain to me how to use these event systems and ui modules to accept inputs from different users?

I figured it out. I will post the solution here for anyone trying to achieve the same behavior. Basically, what needs to be in the scene is:

  • The different player characters, each with a PlayerInput.
  • A single UI Canvas with Event System and Input System UI Input Module.
  • A single InputActionAsset with 2 actions maps (Gameplay and Menu)

What needs to happen when the game is paused:

1- Deactivate the inputs of all the characters except the one who paused the game using PlayerInput.Deactivate()

2- Use PlayerInput.SwitchCurrentActionMap(“Menu”) on the character who paused the game.

3- Assign the action map instance of the player who paused to the Input Sytem UI Input Module using: InputSystemUiInputModule.ActionsAsset = PlayerInput.actions

@Pangamini I’ve found away to have all inputs control a single menu. Very similar to @AlbertoVgdd.

  • Each PlayerInput also has a MultiplayerEventSystem and UI Input Module
  • There are no other event systems in the scene


The ‘Player Input’ Component must have the UI Input Module added. The UI Input Module must have the action asset for THIS specific player. You can do this manually by dragging and dropping the components into their respective fields.

You can also do it via script when the player joins. The ‘Player Input Manager’ is it’s own object and is setup like so:

199970-input-manager.jpg

The ‘JoinNewPlayer’ function contains this:

playerInput.GetComponent().actionsAsset = playerInput.actions; playerInput.uiInputModule = GetComponent();

Once those are hooked up each player can trigger UI events individually. That means when you open a menu ALL event systems have to focus on some menu item. You can use a foreach loop to do this:

foreach (MultiplayerEventSystem eventSystem in FindObjectsOfType()) { eventSystem.SetSelectedGameObject(menuItem); }

Of course ‘menuItem’ has a reference already to the Button in the UI.

1 Like

https://docs.unity3d.com/Packages/com.unity.inputsystem@0.9/manual/UISupport.html?_ga=2.120387531.239237062.1619894930-120019661.1587610245

I found this from a forum thread:
https://forum.unity.com/threads/request-tutorial-or-guide-on-how-to-use-the-new-multiplayer-event-system.736787/

Also, here is a recent video:
https://www.youtube.com/watch?v=81GecyuNapg

Also another video tutorial on creating local multiplayer intput:
https://www.youtube.com/watch?v=_5pOiYHJgl0

If anyone still have this problem, I solved it by simply making the button interaction from scratch. When the game is paused and the player press the arrows on the keyboard or the gamepad, it call a method that change the current selected button from the event system. And then you just need another method that clicks the current selected button.

I know its a mess but it works and you don’t need to use multiple canvas. Also @Pangamini both players can control the screen at the same time.

public void SelectButton(bool goUp)
{
      var buttonSelected = eventSystem.currentSelectedGameObject.name;
  
      if(buttonSelected == "Resume button")
      {
          if (goUp)
          {
               eventSystem.SetSelectedGameObject(quitButton);
          }
          else
          {
              eventSystem.SetSelectedGameObject(mainMenuButton);
          }
  
      }
      else if (buttonSelected == "Main menu button")
      {
          if (goUp)
          {
               eventSystem.SetSelectedGameObject(resumeGameButton);
  
          }
          else
          {
              eventSystem.SetSelectedGameObject(quitButton);
          }
  
      }
      else if( buttonSelected == "Quit game button")
      {
          if (goUp)
          {
              eventSystem.SetSelectedGameObject(mainMenuButton);
          }
          else
          {
              eventSystem.SetSelectedGameObject(quitButton);
          }
  
      }
      else { Debug.LogError("Button not found."); }
  }