Home > Software engineering >  Network Client use wrong input devices when using Unity.Netcode with Starter Asset Controller (New i
Network Client use wrong input devices when using Unity.Netcode with Starter Asset Controller (New i

Time:12-14

The server is always using Keyboard and Mouse just fine.

The client however always use "xbox controller" instead of Keyboard & Mouse:

The following is the inspector view as a client:

enter image description here

The Start Asset input action are unchanged, enter image description here

This is what I tried but client is still being assigned to controller:

private void Start()
{
    if (!IsOwner)
    {
        Destroy(GetComponent<PlayerInput>());
    }
}

How could I fix this? Other than hard coding (PlayerInput)map.SwitchCurrentControlScheme("KeyboardAndMouse");?

CodePudding user response:

This issue is fixed by disabling Player Input script.

And only enable it on Network Spawn.

    public override void OnNetworkSpawn()
    {
        base.OnNetworkSpawn();
        if (IsOwner)
        {
            _playerInput = GetComponent<PlayerInput>();
            _playerInput.enabled = true;
        }
    }
  • Related