Search Unity

Local Multiplayer

Discussion in 'Input System' started by deathbydragon, Sep 10, 2019.

  1. deathbydragon

    deathbydragon

    Joined:
    Mar 4, 2016
    Posts:
    54
    Hi, I am trying to make a local multiplayer game using 2 PS4 controllers as input. One should control each player. I want to use the new input system, and I currently have it set up for one player but I am not sure how to move forward from here.

    Here is what I have now:

    devenv_DlnQRqsi9b.png Unity_aBF23t2ibZ.png
     
  2. BindingForceDev

    BindingForceDev

    Joined:
    Aug 13, 2014
    Posts:
    40
    Hey! This was my solution. I posted this in another thread, and I'm a lazy programmer so here is the copy and paste. I found that this is a reliable way to handle multiple users, for any type of device really, though this is a preview build still so there are some limitations.

    "I dunno if this helps, but I used the PlayerInputManager to automatically spawn new prefabs with PlayerInput scripts attached when devices are recognized (an option in the component). On that instantiated prefab I attached a custom script I called PlayerControls that generates its state from its PlayerInput by doing the same thing the OP does in awake. Finally, when I spawn a controllable player gameObject I reference the PlayerControls script I want to control that player. You can use the onDeviceGained/Lost delegates in PlayerInput to execute actions when input is gained or lost. I have found that certain controllers work really well when input is lost or regained, but it seems auto-handling lost/regained inputs and isn't fully robust or complete in the 0.9.6 preview. For instance, my Switch Pro Controller acts rather strangely in general (especially wired or when Steam is running), while my Xbox 360 controllers have no issues regaining and losing input."

    Here is the original post I was referring to!!! https://forum.unity.com/threads/handling-multiple-controllers.738818/

    Essentially the Player script you have corresponds to my PlayerControls script I describe above. Attach it to a prefab that has the PlayerInput component. Have a GameObject with the PlayerInputManager component in your scene and choose the 'Join Players When Button Is Pressed' behaviour and drop your prefab into the 'Player Prefab Field'. You can use the PlayerInputManager.onPlayerJoined/Left and PlayerInput.onDeviceLost/Regained delegates to get the nitty gritty of assigning controls to the right characters and UI stuff or whatever.

    I hope this helps! I'm in a rush atm but can upload some script examples later if you want.
     
  3. deathbydragon

    deathbydragon

    Joined:
    Mar 4, 2016
    Posts:
    54
    @Funkenation Hi, sorry for the late reply and thanks for what you shared so far. However, I don't really know how you would go about doing the "nitty gritty" of assigning controllers. That is the info I have had a hard time coming across