Search Unity

MLAPI with Unity Input System?

Discussion in 'Netcode for GameObjects' started by jonreeves350, Apr 23, 2021.

  1. jonreeves350

    jonreeves350

    Joined:
    Jul 15, 2019
    Posts:
    2
    Hello all,

    The new input system is very tricky to use with MLAPI?

    I'm a complete beginner in the realms of multiplayer so I'm not sure if I'm mistaken.

    In the old input system the input calls were found (mostly) in the update loops in the game. If you had 2 player objects in the game they would both be moved by any player input. Because of this with MLAPI its very easy to say 'if (!isLocalPlayer)' don't do the update stuff.

    However, with the input system, unity only allows the control of one player instance at a time. When testing this with the same theory as the old input system the host can move freely on the server but the client can't do a thing because their instance of the game is trying to control the host player. Since the host player is not owned by the client their inputs are ignored.

    Does anyone know how you would go about either getting both instances to receive inputs from the 'same' controller (gamepad 1) or how to make that gamepad control the correct instance of the player prefab in the game?
     
    barisdincer likes this.
  2. jonreeves350

    jonreeves350

    Joined:
    Jul 15, 2019
    Posts:
    2
    I found a youtube tutorial that is really helpful for this.


    In the tutorial he uses OnStartAuthority(), instead I used OnNetworkStart() and if(isLocalPlayer) which gives the same result

    Hope this helps anyone else with the same problem.
     
    barisdincer likes this.
  3. batincan

    batincan

    Joined:
    Apr 25, 2019
    Posts:
    1
    add this to Start


    #if UNITY_EDITOR
    (PlayerInput) map.SwitchCurrentControlScheme("KeyboardAndMouse");
    #endif