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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Local multiplayer best practice

Discussion in 'Input System' started by Deleted User, Dec 26, 2019.

  1. Deleted User

    Deleted User

    Guest

    I am doing some exploatory programming for a local multiplayer project.

    I want the player to connect, select an avatar and then that avatar comes with a specific control scheme. This avatar should be re-selected if the player re-connects.

    I would like to create several InputAction assets and switch between them, according to the player choice.

    What would be the reasonable way to create the multi-controller setup architecture using the Input System features? I am mostly concerned about assigning controllers and switching the input actions: should I go switching action maps instead?
     
    qball13z likes this.
  2. ZexScal4

    ZexScal4

    Joined:
    May 25, 2018
    Posts:
    8
    I don't know much about this but you should take a look at this.

    There is a method in PlayerInput called
    SwitchCurrentControlScheme(String, InputDevice[])
    it can switch between Control Schemes that you've created. So you could have one input actions and create several different Schemes and switch between them using whatever logic you'd need.

    Here's a link to the documentation I read where it mentions this:
    https://docs.unity3d.com/Packages/c...String_UnityEngine_InputSystem_InputDevice___

    For more explanation on the function it should be at the top of the document.
    Hope that helps
     
    Static4242 likes this.
  3. Deleted User

    Deleted User

    Guest

    Thank you.

    My current plan is to use PlayerInput as the component that handles the player for each of the avatars, then use a component and a central component which instantiates the avatar prefab and handles its lifetime.

    My two current conundrums are:
    • device serials seem to be empty strings for both xbox one and ps4 controller
    • cannot cleanly detect both reconnection and adding, as adding event always fires and reconnection fires after that one. it doesn't help that the controller gets a new internal id on each connection
    EDIT: after some reading it's apparent that persistent IDs for controllers are practically impossible and thus I will likely just drop the feature that lets you reconnect without a hassle
     
    Last edited by a moderator: Dec 28, 2019
  4. ZexScal4

    ZexScal4

    Joined:
    May 25, 2018
    Posts:
    8
    if its about having the player join and leave then perhaps take a look at player input manager component. That is basically what it does. Though its features at the moment are a bit limited from what I know but I haven't looked into it that much.