Search Unity

NOOB: Proper location/scope of Input System UI Input Module

Discussion in 'Input System' started by Nathanieljla, Nov 14, 2020.

  1. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    I've seen almost no information about the Input System UI Input Module and I'm struggling to understand a few basic things about it and how it works with playerInput.UiInputModule. Even in the input warrior demo they don't initialize the playerInput.UiInputModule.

    This game will have local co-op so I'm looking at this in terms of multiple users. I'm aware of the player input manager and need to replace the event system with the Multiplayer event system.

    Questions:
    1. Am I understanding correctly that the playerInput.UiInputModule is really only there to make sure the Input System UI Input Module is always in sync with whatever input the player is using?

    2. Is it one Input System UI Input Module per user or one Input System UI Input Module per canvas? (saw someone online doing it one per canvas.

    3. Where do you place the Input System UI Input Module? I originally figured I'd just keep it on the same game object as my player input component and Unity was exploding with system errors when trying to run. I tried adding all the listed event handlers like "OnSubmit" (I'm using send message), but nothing fixed it until I moved it to a different object. I saw a few other people who had the same experience. Why would this matter?

    Thanks.
     
    sarynth likes this.
  2. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    I'm still looking for some help on this if anyone has any experience.
     
  3. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    First thing's first, you'll want an EventSystem in one of your scenes at runtime.
    Without an EventSystem, your inputs will be recognized by Unity, but will NOT interact with any UI/Canvases.

    The component inheriting from BaseInputModule should be able to "understand the input" and translate it to EventSystems events, such as:

    IMoveHandler
    IPointerClickHandler
    IScrollHandler
    IDeselectHandler

    etc.

    This might be outdated documentation, but this explains BaseInputModule well.
    The UnityEngine.UI and UnityEngine.EventSystems namespaces were moved into the Unity UI package (and thus, has its own Unity UI package documentation now)!

    --- --- --- --- ---


    Once you understand what those components do, here's my style for organizing them (usually):

    I typically have 1 EventSystem in a UI scene that is kept additively loaded throughout the entire gameplay session (same effect as GameObject.DontDestroyOnLoad(...) to keep 1 EventSystem activated at all times).

    From my understanding, you should also have a component that inherits from BaseInputModule attached to your EventSystem game object, meaning you'll also have 1 (if you do the same, and keep just 1 EventSystem).

    --- --- --- --- ---


    By default, the EventSystem comes with a StandaloneInputModule that handles keyboard and mouse input for Window/Mac/Linux. It "understands input" using the UnityEngine.Input (old) API.

    However, if you'd like your EventSystems events to be interpreted from the newer and more robust UnityEngine.InputSystem API, replace this StandaloneInputModule with a InputSystemUIInputModule, and it'll choose a bunch of already-created default InputActions to be hooked up for you!


    I hope this helps clear up the confusion for you! :)
     
  4. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    Thanks for the reply. I'm not sure it completely addresses my questions, but it does provide some good insight. Since my original post I tried this setup => Each player prefab has a:
    1. PlayerInput component
    2. Multiplayer Event System Component
    3. Input System UI Input Module Component
    PlayerInput.UIInputModule points to #3

    The Player Input Manager spawns the characters. The first character works fine. However, when the second character spawn the #3 component's UI events to action mapping gets cleared and I can't interact with the menu.

    I'm really looking for someone who's successfully setup a Multiplayer Event System Component to see how they did it.
     
    ModLunar likes this.
  5. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    374
    Ahh I see your problem a little clearer now.
    I'm working on a multiplayer game, but it's fully networked (no local co-op), so I haven't run into this issue yet (each player's client only needs 1 EventSystem).

    Goodluck!
    I hope someone can provide more help in this area.
     
  6. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    If anyone could look at the attached package I would love for someone to tell me what I'm doing wrong. To use the package:
    1. Create a universal pipeline project, install the new input system.
    2. Import package and load the scene MP_Menus.
    3. Click the mouse button to spawn player 1 (m on the keyboard toggles the level menu).
    4. Hit a button on the joystick to spawn player 2 (options button toggles level menu).

    Here's the issues I'm facing.
    1. Character prefab 1 spawns correctly, but not character 2. Character 2 has a child named "UI_System" It has a UI Input Module component, but all of the ui events to action asset mappings are cleared.

    2. The mouse interacts with the menu of the joystick character (I tried changing the mp even system player root, which didn't help).

    3. The joystick character, with a little fiddling around, interacts with the other character's menu.

    ________Project setup_____
    1. ActiveLevel.cs contains a reference for the menu to spawn on the character prefab.
    2. When the character hits the menu button it gets an instance of the level menu and parents it under it's UI_System child then setups up the menu info. Stuff like the character camera, and what object should be selected first.
     

    Attached Files:

  7. JulianBruxelle

    JulianBruxelle

    Joined:
    Feb 8, 2020
    Posts:
    3
    Hey, same problem here, can't get it to work properly...
    I loose focus with gamepad on menu change (i'm using Peeweek's State Machines (Gameplay Ingredients) for menus, but Input Modules and events system are outside disabled menus).

    If anyone has an answer to our problems. :confused: