Search Unity

Bug Input Action Asset gets unassigned from instantiated prefab

Discussion in 'Input System' started by DivineRage, Nov 12, 2020.

  1. DivineRage

    DivineRage

    Joined:
    Jun 20, 2014
    Posts:
    1
    I'm having a strange issue where the actions reference on PlayerInput components gets unassigned.

    When I first start unity, and instantiate this prefab, everything is fine. I drag this prefab into the scene;

    upload_2020-11-12_14-18-42.png

    And everything works.
    upload_2020-11-12_14-24-56.png

    Then I hit play, that already existing character gets assigned to M/KB controls just fine. I stop playing and everything is still fine.

    If I go back into play mode, and press "A" on my xbox controller, it creates another instance of that prefab. Everything is still working fine. However, if I now exit play mode, that reference gets unassigned.

    upload_2020-11-12_14-27-47.png

    After that, any other time that I instantiate one of those prefabs, in editor or when the PlayerInputManager does it during gameplay, it will no longer have an assigned InputActionAsset. And therefore controls stop working for newly created characters.

    Does anyone have any ideas what's going on here? And more importantly, how to prevent it from happening?

    Unity 2020.1.10f1, Input System v1.0.0 (though I've tried v1.1.0-preview.2 without observing any change)
     
    Last edited: Nov 12, 2020
    Quazaar_studios likes this.
  2. Nathanieljla

    Nathanieljla

    Joined:
    Apr 18, 2014
    Posts:
    97
    Did you find any solution to this? I'm running into a similar issue. I've noticed at the project level the Input Action Asset will reset/clear to None (it feels random, but I'm sure it's not).

    I'm also running into with the Input System UI Input Module's mapping clearing, which is reproducible.

    1. I have a prefab in my scene. The root has a playerInput. A child game object has Input System UI Input Module. Both are assigned the same input action asset and the Input System UI Input Module is assigned to the playerInput. This object is disabled.

    2. Another object has a Player Input Manager It's prefab references the Instantiated prefab listed above. (Originally the Player Input Manager referenced the prefab at the project level, but since the action asset was being unassigned I figured a instance at the hierarchy level would around the issue.)

    3. Start the game, tap the keyboard and the first character spawns. Tap the joystick and the second character spawns, but at this point the second instance's Input System UI Input Module's mappings are cleared and I can't interact with the menu.
     
    Quazaar_studios likes this.
  3. fabr-IQ

    fabr-IQ

    Joined:
    Dec 16, 2012
    Posts:
    1
    I'm seemingly encountering the same issue with Unity 2020.1.7f1 and version 1.0.1 of the Input System.


    Update:
    I did some more testing, and it only seems to happen if I spawn two different Player Input prefabs from the Player Input Manager, which I'm doing via my own script because my game is asymmetrical co-op with two different player prefabs. As long as I just spawn the same prefab for each player like the multiplayer sample does, it works fine. Even using variants of the same prefab doesn't seem to work, though.

    I was able to find a workaround by using the same "generic" prefab with Player Input for both characters (they do share a lot of functionality), and then spawning "add-on" prefabs with the custom elements and childing them to the "generic" player prefab when each player joins. It would be a lot more elegant if I could just use variants of the same prefab, but it works.


    Update #2:
    I realize I think I was having a slightly different issue, as mine stemmed from spawning two different prefabs from the Player Input Manager. However, I also think I just reproduced more or less the same issue by having one player (with a Player Input component) already in the scene and spawning a second one via the Player Input Manager. Thankfully this was just something I did by accident while testing and doesn't reflect my intentions, but it was still annoying that it broke the reference to the Input Actions in the prefab.
     
    Last edited: Dec 11, 2020
    Quazaar_studios likes this.
  4. Quazaar_studios

    Quazaar_studios

    Joined:
    Feb 10, 2018
    Posts:
    2
    Any updates guys? I ran into the same issue, when the prefab gets instantiated cuz I press the button to join that prefab doesnt have the input actions asset i attached before, know why this happens?
     
  5. markrestart

    markrestart

    Joined:
    May 29, 2013
    Posts:
    4
    I'm having a similar issue. More so to the situation of fabr-IQ. I am using multiple player prefabs, all sharing the same Input Actions Asset. The first player prefab instantiated works fine. The next two work fine for that session, but as the prefab gets instantiated, the Actions field turns to "Type Mismatch". When I stop playing, it switches to missing and doesn't work on the next play.

    The workaround I'm using is to duplication the Input Actions Asset and give each of them a different one.
     
  6. markrestart

    markrestart

    Joined:
    May 29, 2013
    Posts:
    4
    I came up with a different solution. I have a single prefab with the Player Input component, and a script that can instantiate the actual player prefab on start and then pass the information. Here's a video I made for anyone having this issue.
     
  7. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    This should be fixed as of 1.1-preview.3.
     
    Nathanieljla likes this.
  8. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    6,362
    he's alive!

    @DivineRage I don't recommend using Player input because even in p3 it's got other bugs such as not cleaning up events of deleted actions.
    Better you hard code all input with .WasPressedThisFrame
     
  9. joaorequiao

    joaorequiao

    Joined:
    Oct 15, 2015
    Posts:
    6
    Not fixed on 1.1-preview.3. Still having the same problem. Whenever a different device is used and another Player input is instantiated for it by the Player Input Manager, the Default Input Actions field is reset.
     
  10. bMitchell

    bMitchell

    Joined:
    Jan 25, 2014
    Posts:
    3
    We're trying to champion the engine to higher ups yet I can't Play my scene twice without the core player input system breaking and needing a manual relink. I'm just using Keyboard but we're supporting gamepad, so it doesn't seem related to using multiple unless just having the binds is causing it. But this is maddening.
     
    damm0409 likes this.
  11. Fressbrett

    Fressbrett

    Joined:
    Apr 11, 2018
    Posts:
    97
    Same here... The input system looks initially very good, but when it comes to using multiple devices and having multiple isntances of the PlayerInput, stuff gets weird.

    I am trying to let all players navigate the same UI, but this is not possible out of the box, since the second player gets a clone assigned of the InputActionAsset, which then mismatches the InputAsset referenced in the InputSystemUIInputModule.... this is just a pain to work with, so many roadblocks that drain time and energy to find unclean workarounds... sometimes i am thinking about just using the old system, and managing different devices myself
     
  12. dirogui

    dirogui

    Joined:
    Apr 8, 2020
    Posts:
    1
    i have the same bug
    It only works one time when i open the editor, the second time when i press play, the new character spawn but with the player input manager empty
     
  13. andrew_oc

    andrew_oc

    Unity Technologies

    Joined:
    Apr 16, 2021
    Posts:
    77
    I'm not able to reproduce this on version 1.1.1. Would someone be able to submit a bug report (in Unity Editor -> Help -> Report a bug...) with a repro so we can take a deeper look?