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

User #0's actions are automatically being disabled under certain conditions

Discussion in 'Input System' started by Armetron, Apr 18, 2020.

  1. Armetron

    Armetron

    Joined:
    Oct 7, 2016
    Posts:
    26
    Hello again, I'm going to try my best to explain what is going on in my scene and hopefully it will be clear enough to understand.

    In my project I am currently working on a main title menu Demo that will show a menu of buttons that one of them will lead to a character select menu followed by the the actual game in another scene. In my demo level I have a canvas with two child GameObjects [Main Menu, Character Select] each with their own set of UI elements. The character select 'panel' has 4 UI images that have a script that will change it's color whenever it receives a move event from the multiplayer event system.
    Title Menu Canvas.png Selector UI Component.png
    As you can see every image (selector) has a multiplayer event system and a input module set to use myControls Input Actions. myControls consists of one action map (UI), two actions (Navigation and 'Select) and is setup to use both gamepads and keyboard inputs.

    I have a GameObject called GameManager that on Awake() instantiates 4 prefabs that contain a transform and a player input component set to use myControls input actions with the default scheme set to gamepad. The GameManager parents the player prefabs to itself and adds each one to a reference list accessible to all classes (singleton).

    My UI image component on Start() uses an internal player index int get get the corresponding player input component from the GameManager list. It then sets the player input's UI Input Module to be it's own input module so that each player can control a single selector.

    *whew* ok so now that I explained my setup here is were the confusion/error/bug happens. If I run the game with the character select object disabled as shown in the image the player inputs spawn and the input debug logs 4 users with their respected devices and actions. I then enable the character select object which causes all the selectors to enable and update the input module references in the player inputs. Using this method it works PERFECTLY as expected, I can control each selector individually using a specific device. However if I instead leave the character select object enabled by default the player inputs spawn and their refrences are updated just as before, but for some reason user 0 is reporting to have its input actions disabled in the debugger.
    Input Debugger.png
    I have no idea why and I'm trying to figure it out so I can prevent/avoid it in the future
     
  2. Armetron

    Armetron

    Joined:
    Oct 7, 2016
    Posts:
    26
  3. Rene-Damm

    Rene-Damm

    Unity Technologies

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Hi @Armetron, would you mind filing a ticket with the Unity bug reporter? Think it'd be good for us to take a closer look.

    On a superficial level, the problem comes down to a thing that PlayerInput does where the first PlayerInput will always use the given actions as is whereas every added player will duplicate the actions and thus use a cloned version. So if some other code goes and enables/disables actions in the same set, player #0 is affected by that. In this case, it's probably InputSystemUIInputModule on the UI EventSystem that does the disabling (probably when it is itself disabled).

    We've been going back and forth on whether PlayerInput should be doing that. It does tend to lead to unwelcome surprises. Could be we should just get rid of that or could be there's better ways to have it and yet not have surprises elsewhere.
     
  4. Armetron

    Armetron

    Joined:
    Oct 7, 2016
    Posts:
    26
    @Rene-Damm, I've changed my proto menu around a bit since then. Currently I have a two menu panels, first panel is the main menu that has 4 buttons and can be controlled by everyone and the second panel is the Character select screen that you saw in the video. Unfortunately because of what you mentioned regarding the PlayerInput always taking the given actions I had to make a player controller prefab that has a blank PlayerInput component and I manually create and assign a new InputAsset so the first one does not override the "default".

    I do this because whenever I enable the Main Menu panel, that has an event system input module, it uses the "default" asset that is not bound to any device allowing it to listen to All the devices at the same time.

    While I am in no way an expert and I still haven't figured out all the kinks/tricks needed to achieve my end result. My current use benefits if the PlayerInput component just made its own asset.
     
  5. Fenrisul

    Fenrisul

    Joined:
    Jan 2, 2010
    Posts:
    617
    This has my vote - right now if you make changes with runtime code (in the editor) to any of the non-instanced InputAction's interactions...processors...etc... it bleeds into the permanently serialized InputActionsAsset. I can't think of a case where this is a good thing - as opposed to providing maybe some Editor-only utilities for doing this.

    @Armetron
    I watched your video. In the case of User #0's actions being disabled what is MOST LIKELY going on is this...
    Your PlayerInput components all have a reference back to the Original InputActionsAsset. When the last PlayerInput initializes, if it cannot find a device to bind to, it disables stuff. Because it cannot bind to anything, it disables its InputActions accordingly which are still your original InputActionsAsset (which are properly bound to another user!)

    InputSystem's PlayerInputManager (akin to your own game manager) handles Joining a bit differently - and requires an un-used device to automatically spawn prefab containing PlayerInput so this simply wouldn't come up (unless manually instantiating objects)

    Hope that clears things up a bit!
     
  6. Armetron

    Armetron

    Joined:
    Oct 7, 2016
    Posts:
    26
    @Fenrisul I got around it by having the character select panel turn on the selectors with player input components in order then when changing back to the first panel to first turn off the selectors so the InputActionAsset clones get cleared, the devices get unbinded and the event system on the first panel can start using the serialized asset listening to all the devices again.
     
  7. ModLunar

    ModLunar

    Joined:
    Oct 16, 2016
    Posts:
    372
    For some reason, even though I enable the InputActionMap I'm using,
    my actions (part of that map) were still disabled and not working with me hooking onto the performed event.

    The solution in my case was I needed to enable the individual InputActions as well.
    (accessible via the InputActionMap's actions property, OR
    via a [SerializeField] private InputActionReference yourVariableName)



    I've never had to do this before, but I don't have time to better-understand the API right now.
    I guess it's because I've been mostly been using the PlayerInput component's SendMessage approach.
    Today, I've been hooking on to the InputAction's performed event, which might work slightly differently.
     
  8. unity_418scarlet

    unity_418scarlet

    Joined:
    Aug 1, 2021
    Posts:
    7
    Hi Rene, I got a similar problem, When i respawn the player the imput system appear disabled and so also the collider. But regarding the collider i just get the component and enable it after the spawn but it seems that i cannot do the same with the Input System.
    Any suggestions ?
    Thank you
     
  9. Grzp

    Grzp

    Joined:
    Jan 25, 2018
    Posts:
    31
    Hi, probably I found a solution for this bug.

    First, for player prefab where I have PlayerInput component, I set Default Map for None (I do that but it's not necessary), and on start function I disable all map, and next I set current map and enable it. I also do it when I change the scene.
    For me it works on start scene and also on next 2 scene.
     
    Last edited: Jan 27, 2022