Search Unity

Question The new Input System Package doesn't seem to work with Mirror Networking API

Discussion in 'Input System' started by Sparkwave, Aug 13, 2020.

  1. Sparkwave

    Sparkwave

    Joined:
    Oct 5, 2016
    Posts:
    1
    Everytime I spawn 2 players (one host and one client) with the package, the Player Input component on the host looks like this:

    It works perfectly fine and reads the inputs from the device. However, the Player Input component on the client looks like this:

    Note the missing "Control Scheme" and "Devices" in the "Debug" subcategory, and "Controls(Clone)" instead of "Controls" as "Actions". The client also doesn't seem to register any inputs at all.
    What should I do for the client to register the same inputs as the host?
     
    mingkimlow and dannyalgorithmic like this.
  2. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    This is an annoying issue
     
  3. Muze

    Muze

    Joined:
    Nov 14, 2018
    Posts:
    1
    I had the problem and i managed to fix it by changing the active input handling to both, you'll find that in Build Settings > Player Settings > Player > Other Settings > Active input handling.
     
    evort22282 and m8o like this.
  4. m8o

    m8o

    Joined:
    Nov 8, 2020
    Posts:
    2
    Is there a solution that doesn't require changing Active Input Handling? I have the exact same problem as OP but I'd like to use the new input system only.
     
  5. horstii

    horstii

    Joined:
    Dec 4, 2020
    Posts:
    1
    Hi, I am using the new input system and was facing the same issue now. I solved it like this:
    Dont use the editor, create a PlayerInput add the component and load it from Resources.
    Create also the InputAction within the script.
    Also add the ControlScheme and Action Map manually.
    I played around and it seems to work now with this, but I have to check if I have forgotten something, or some stuff is redundant/not necessary. Example for 2 InputActions (Up Keyboard Key and Down Keyboard Key):
    Code (CSharp):
    1.  
    2.   void Start()
    3.   {
    4.     if (isLocalPlayer || isClient)
    5.     {
    6.       PlayerInput playerInput = gameObject.AddComponent<PlayerInput>();
    7.       playerInput.actions = Resources.Load<InputActionAsset>("SimpleControls");
    8.       playerInput.defaultControlScheme = "KeybControlScheme";
    9.       playerInput.defaultActionMap = "SimpleControl";
    10.       playerInput.SwitchCurrentControlScheme("KeybControlScheme");
    11.       playerInput.SwitchCurrentActionMap("SimpleControl");
    12.       playerInput.notificationBehavior = PlayerNotifications.InvokeUnityEvents;
    13.  
    14.       Down = playerInput.actions["Down"];
    15.       Down.performed += context => OnDownKeyPressed(context);
    16.       Up = playerInput.actions["Up"];
    17.       Up.performed += context => OnUpKeyPressed(context);
    18.       playerInput.onActionTriggered += HandleAction;
    19.       playerInput.ActivateInput();
    20.     }
    21.   }
    22.  
     
    Skyjengi and dannyalgorithmic like this.
  6. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    I am going to try this! :-D
     
  7. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    Thank you so much, man!!!!!!
    This resolved a ton of issues I was having.

    Although I set my code up in the StartLocalPlayer method since the PlayeInputScript isn't need on either the other clients or server. :)
     
  8. CanardCoinCoin

    CanardCoinCoin

    Joined:
    Oct 5, 2018
    Posts:
    3
    Hey, sorry to post so late, but today I was facing the same problem and I think I found an easier and cleaner way to fix it. Instead of creating the whole component through code, I simply disabled the component from the prefab, and enable it when the gameObject is instantiated, using this :

    Code (CSharp):
    1. public override void OnStartAuthority()
    2.     {
    3.         base.OnStartAuthority();
    4.  
    5.         UnityEngine.InputSystem.PlayerInput playerInput = GetComponent<UnityEngine.InputSystem.PlayerInput>();
    6.         playerInput.enabled = true;
    7.     }
    With this Mirror method, the component is enabled only for client owning the prefab, and it seemed to resolve the problem entirely. I tested it with host/client + client, and server-only + 3 clients, works fine in every case. I'm using SendMessages() though, not Unity events.
    I had to use UnityEnfine.InputSystem.PlayerInput, as writing merely "PlayerInput" was forcing me to use a struct contained in the Unity Class PlayerInputController (weird you guys didn't seem to have this problem btw, maybe due to my Visual Studio's preferences, or because of Unity 2020?)

    Maybe this will help you or somebody else passing by!
     
    Last edited: Jan 18, 2021
  9. dannyalgorithmic

    dannyalgorithmic

    Joined:
    Jul 22, 2018
    Posts:
    100
    Thanks a ton, man. :-D
     
    CanardCoinCoin likes this.
  10. jinzhouliu4

    jinzhouliu4

    Joined:
    May 19, 2020
    Posts:
    1

    THANKS MAN
     
  11. lucassaldanha

    lucassaldanha

    Joined:
    Mar 11, 2014
    Posts:
    3
    This worked for my project. Thanks!
     
  12. Solias99

    Solias99

    Joined:
    Jul 1, 2021
    Posts:
    3
    Worked like a charm. Thanks!
     
  13. jonmar912

    jonmar912

    Joined:
    Aug 31, 2020
    Posts:
    1

    Oh my gosh.

    I love you.
     
  14. luisfdo16_1

    luisfdo16_1

    Joined:
    Jan 19, 2014
    Posts:
    1


    Thanks a lot man !!!
     
  15. a1creator

    a1creator

    Joined:
    Jan 18, 2021
    Posts:
    24
    THANK YOU SO MUCH !!! May you be blessed for the rest of your days
     
  16. happyfirecn

    happyfirecn

    Joined:
    Dec 28, 2016
    Posts:
    11
    Excellent! Works for me. Thanks!
     
  17. KeithSeraph

    KeithSeraph

    Joined:
    Jun 30, 2015
    Posts:
    1
    Another alternative that I used was to simply put my PlayerInput component on a separate local GameObject and populated it in my spawn method whenever the player chose a character. I'm currently using Netcode.
     
  18. TtroubleTT2

    TtroubleTT2

    Joined:
    May 2, 2023
    Posts:
    2
    I literally love you. Thank you so much.