Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Having Multiple Player Inputs on Scene?

Discussion in 'Input System' started by Ziberian, Jan 16, 2022.

  1. Ziberian

    Ziberian

    Joined:
    Jan 9, 2018
    Posts:
    66
    Hey everyone,

    On my scene I had multiple player input components (screenshot below). One on the player, one on the game object responsible for pausing the game (since I pause with the ESC key), and more.. I am not sure if that is bad design or okay, but I realized the "Auto-Switch" function is automatically disabled if there are multiple components in the scene. I need that functionality to potentially have gamepad controls in my game.

    So I decided to remove all but 1 Player Input components from the scene, and I thought I could have every other object use the same component by reference. This worked with every single button except the Mouse Position.

    upload_2022-1-16_17-8-37.png

    I read the Mouse Position as a Vector2 to help my player aim and shoot at the direction. With the old system it worked normally, I even did a Debug.Log(mousePosition), and I would see the Vector2 move around correctly as I move my mouse around.

    The problem is when I switch into the new system (with only one Player Input component), every button works but the mousePosition reading is always at Vector2(0, 0). Does anybody have any idea why?

    What I even tried was I loaded up my old scene (with multiple Player Input components). Then I switch the Input Action Asset to a single one, and the same thing happens: every button works but mouse position is stuck at 0, 0 now.

    Has anyone dealt with this before? Any help is appreciated.

    Best,
    Ziberian
     
  2. Ziberian

    Ziberian

    Joined:
    Jan 9, 2018
    Posts:
    66
    I have found the issue...

    If you go and open your Input Debugger (Window -> Analysis -> Input Debugger)

    I saw that the user only had Keyboard under paired devices:

    upload_2022-1-16_18-5-10.png

    and in order to add a mouse there what I had to do was go to Input Actions editing window. On the top left choose Keyboard scheme (the name might be different for you, but choose the scheme that is to be used with a keyboard and mouse). Click Edit Scheme.

    upload_2022-1-16_18-6-5.png

    In there make sure you have Keyboard AND Mouse added (I only had Keyboard before).

    upload_2022-1-16_18-6-23.png
     
  3. X3doll

    X3doll

    Joined:
    Apr 15, 2020
    Posts:
    33
    Hi! I'm curious, it's actually possible? I remember that you can bind one set of device per component. Did you make it works?

    I'm driving crazy to have multiple input source per scene/contexts