Search Unity

Player Input Manager join action not working

Discussion in 'Input System' started by Saucyminator, Jun 21, 2020.

  1. Saucyminator

    Saucyminator

    Joined:
    Nov 23, 2015
    Posts:
    61
    Hi.

    Trying to setup multiple controllers to use the Player Input Manager. I've created a prefab with PlayerInput script on it. And setup a button for joining the game in the input action asset (spacebar/button south).

    If I've set the Player Input Manager component join action to use a reference, only one controller joins when pressing the join button. If I uncheck it and use actions I've setup on the component directly, the controllers join as expected.

    Is this a bug or intended?

    Unity v2019.4
    InputSystem v1.0.0
    URP
     
  2. lassade

    lassade

    Joined:
    Jan 27, 2013
    Posts:
    127
    Same problem here using Unity 2020.1.3f1, Input System v1.0.0
     
  3. RR7

    RR7

    Joined:
    Jan 9, 2017
    Posts:
    254
    i think i'm seeing this problem too (2020.1.4), if the join behaviour is set to join player when a button is pressed its fine, but if i choose a join action and bind it to an action only the first controller works. this happens even using the unity multiplayer sample in the package. what am i missing here?
     
  4. RR7

    RR7

    Joined:
    Jan 9, 2017
    Posts:
    254
    okay so this seems not to be a new 'problem' - its been reported on the web for months now and apparently a support ticket was closed. it's 1.0.0 and released now, so can someone from unity please please please either explain why this doesn't how we seem to think it should work, or what's going to be done about it if its not working as intended.
     
  5. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    Got the same issue. I was sure I posted a bug report then realized I wanted to wait to test it on Windows (I was on Linux) before reporting it. Sorry, we could have gained some time if I had posted it earlier... I'm going to test once more today and report if needed.

    Actually I tried to find the cause of the issue by debugging the source code esp. the JoinPlayerFromActionIfNotAlreadyJoined method, but got lost in the code and couldn't find a reason.

    @RR7_ can you reference the close issue for web?
    I found one for Xbox I thought to be similar https://issuetracker.unity3d.com/is...game-if-it-is-the-second-one-to-be-plugged-in but it was different as it mentioned the gamepad plugged first, and in our case plug order doesn't matter, the order in which players try to join matters.

    UPDATE: arg, need to check if the bug is only within the Editor or also in the standalone Player before submitting
    Also got issues with my MWP where they ask me to sign in with a glitchy button so I can't easily install the Input System package from UI... I may send the bug report without an example project in the end. Or I'll send our actual project, as it's not too big...
     
    Last edited: Oct 20, 2020
  6. RR7

    RR7

    Joined:
    Jan 9, 2017
    Posts:
    254
    They have a bug case here which i have added a vote for:

    https://issuetracker.unity3d.com/is...riggered-when-using-a-referenced-input-action

    the ticket i mentioned as closed wasn't mine it was something i read somewhere on the forums.

    this seems like quite a big flaw to me as i'm used to working with Rewired which has similar action events, but i really want to be able to use the nice input system feature where a gaming profile gets attached to the player (xbox live etc)
     
  7. huulong

    huulong

    Joined:
    Jul 1, 2013
    Posts:
    224
    Thanks, I added some info about issue being with the second player to join. And added my vote (now we're 2...)
     
  8. Zelgadis87

    Zelgadis87

    Joined:
    Nov 14, 2016
    Posts:
    6
    I think this is because the first player joined "steals" the join action for itself from the InputAsset, such that every time the action is pressed again, the instantiated PlayerInput receives it instead of being fired globally on the manager.

    It seems that I've solved the problem on my project by disabling the new PlayerInput as soon as it is created, and wait for the required number of players to be there before re-enabling all of them.
     
  9. RR7

    RR7

    Joined:
    Jan 9, 2017
    Posts:
    254
    That's a good shout, I've not really picked up on how the PlayerInput scripts are supposed to sit in the hierarchy of things. I have been using rewired for a while and this seems similar in some ways and then way out there in others. I only need a join function in the UI/lobby, it feels like I need a unique script for that and not the PlayerInput example that's provided.
     
  10. VoltDriver

    VoltDriver

    Joined:
    Nov 16, 2019
    Posts:
    7
    Oh my god, thank you! This fixed the problem I had!

    It's totally the problem. I did something like this:

    for(int i = 0; i < _playerCount; i++)
    {
    PlayerInput spawnedPlayer = _playerInputManager.JoinPlayer(playerIndex, playerIndex);
    spawnedPlayer.enabled = false;
    }

    And then later I reenable all of the PlayerInputs.

    And it works perfectly now. You need to disable the PlayerInput on your player right after joining it, and then later on re-enable it.

    Thank you SO MUCH for leaving your theory here on the forum, saved me a huge headache.
     
  11. hk0i

    hk0i

    Joined:
    Feb 11, 2022
    Posts:
    3
    I've been debugging this issue for like a week straight, disabling on join seems to work, right now I'm just re-enabling manually in the inspector.

    In my case I have a `SpawnPoint` component (script) which is spawning the prefabs individually one at a time, so I'm not sure how to wait for this to finish since the order isn't guaranteed. Actually in my case the Player 2 spawn triggers before the Player 1 spawn.

    Where do you guys actually reenable the `PlayerInput`?