Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Type of instance in array does not match expected type

Discussion in 'Input System' started by Antilight, Aug 9, 2022.

  1. Antilight

    Antilight

    Joined:
    Oct 19, 2018
    Posts:
    7
    I just upgraded my project from 2021.3.7f1 to 2021.3.8f1. Now I keep getting this error message when running my game.


    It doesn't seem to cause any problems in my game but it's annoying and makes it harder to read the console. I can't find any posts online for how to fix it so I'm asking here.

    Edit:
    Reverting the editor back to 2021.3.7f1 and the InputSystem back to 1.3 is the only solution I could find so far.
     
    Last edited: Aug 10, 2022
  2. jmastorm

    jmastorm

    Joined:
    Aug 5, 2019
    Posts:
    7
    I'm facing the same problem in 2021.3.8f1 after upgrading. I need to switch between different input systems in the app, and this error is thrown when disabling a GameObject with PlayerInput attached.

    The error comes from PackageCache\com.unity.inputsystem@1.4.1\InputSystem\Actions\InputBindingResolver.cs line 638: Debug.Assert(type.IsInstanceOfType(array[count]), "Type of instance in array does not match expected type");

    A workaround is to use direct reference to the PlayerInput class instance and use enable/disable.


    var playerInputs = GetComponent<PlayerInputs>();
    playerInputs.enabled = false;
     
  3. CausticLasagne

    CausticLasagne

    Joined:
    Oct 2, 2015
    Posts:
    26
    +1 can confirm this is on the latest version of Unity. It doesn't seem to be any configuration of my scripts or the input manager. I can't debug because its in the package manager.
     
  4. Tazadar66

    Tazadar66

    Joined:
    Aug 27, 2013
    Posts:
    57
    Same error, is there any fix so far? If I disable Player Input it throws the error again...
     
  5. Hypertectonic

    Hypertectonic

    Joined:
    Dec 16, 2016
    Posts:
    75
    This error is really annoying. It's still showing up in Input System 1.4.2
    Had to revert to 1.3.0.
     
    Alvarden and umbrella-crash like this.
  6. jamesyoung79

    jamesyoung79

    Joined:
    Aug 22, 2012
    Posts:
    5
    This seems to be an issue with template for editor version 2021.3.8f1. The one included with editor version 2021.3.5f1 it does not happen.
     
    umbrella-crash likes this.
  7. erikDo

    erikDo

    Joined:
    Aug 22, 2022
    Posts:
    1
    The workaround by @jmastorm didn't work for me. I wrote a similar one. Just put this script above the PlayerInput component causing the issue:
    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.InputSystem;
    3.  
    4. public class PlayerInputErrorWorkaround : MonoBehaviour
    5. {
    6.     private PlayerInput Input;
    7.    
    8.     private void Start()
    9.     {
    10.         Input = GetComponent<PlayerInput>();
    11.     }
    12.  
    13.     private void OnDisable()
    14.     {
    15.         Input.actions = null;
    16.     }
    17. }
    18.  
     
  8. MarkeMark1972

    MarkeMark1972

    Joined:
    Feb 14, 2015
    Posts:
    5
    Thanks, @erikDo. This worked perfectly for me.
     
  9. Hypertectonic

    Hypertectonic

    Joined:
    Dec 16, 2016
    Posts:
    75
    Wait, so reordering components also affects their execution order? Had never realized this before o_O

    Anyway this worked for me, thanks
     
    Last edited: Sep 3, 2022
    larry2013z likes this.
  10. yitz_unity

    yitz_unity

    Joined:
    Jun 22, 2021
    Posts:
    12
    Just upgraded to 1.4.2 and getting this error. What exactly is causing this error? The workaround above is not working for me.
     
    Last edited: Sep 7, 2022
  11. pheckinger

    pheckinger

    Joined:
    Jan 24, 2022
    Posts:
    5
    Zaddo and yitz_unity like this.
  12. dragonalumni

    dragonalumni

    Joined:
    Jun 25, 2021
    Posts:
    31
    Using the 3d tutorial and adding an empty script and nothing else was enough for me to get 7 messages relating to PlayerInput.cs

    Unfortunately for me, this is happening all over the place for me, using 2d or 3d tutorials with a lot of pre-packaged code, works fine. Make a little bit of code in a new script and boom the whole house of cards comes down, though, somewhere else. It also appears to be totally unrelated and it's always the pre-packaged code that bombs.
     
    Last edited: Sep 16, 2022
  13. FableStudio

    FableStudio

    Joined:
    May 18, 2018
    Posts:
    2
    Downgrading to Input System 1.3.0 did the trick for us.
     
    umbrella-crash and Alvarden like this.
  14. poprev-3d

    poprev-3d

    Joined:
    Apr 12, 2019
    Posts:
    71
    Same with unity 2021.3.9f1 and latest Unity Input System 1.4.2. Will downgrade
     
  15. Reahreic

    Reahreic

    Joined:
    Mar 23, 2011
    Posts:
    254
    umbrella-crash likes this.
  16. imagoFX

    imagoFX

    Joined:
    Sep 19, 2011
    Posts:
    84
    I've added // in front of the line that sends the error message - the script is InputBindingResolver.cs in Library\PackageCache\com.unity.inputsystem@1.4.1\InputSystem\Actions
    It might prevent the script from throwing real errors but... fixed this issue for now.
     
  17. imagoFX

    imagoFX

    Joined:
    Sep 19, 2011
    Posts:
    84
    ...and that didn't help
     
  18. Reahreic

    Reahreic

    Joined:
    Mar 23, 2011
    Posts:
    254
    Whenever I edit a packages source, I get the message: "The package cache was invalidated and rebuilt because the following immutable asset(s) were unexpectedly altered" and it gets reset. I guess I need to edit not only the package in the editor, but also the one in the download cache.
     
  19. REDACT3D_

    REDACT3D_

    Joined:
    Nov 8, 2020
    Posts:
    222
    FYI: for anyone getting this error, try this:

    Inside Project Settings > InputSystem: I found this huge button labeled Create Settings Asset.
    Did not receive an error after generating the script.

    Capture.PNG
     
  20. Reahreic

    Reahreic

    Joined:
    Mar 23, 2011
    Posts:
    254
    I already use the auto generated asset. I wonder if your post indicates that it needs to be deleted to force a full re-generation? Will try later today.
     
  21. poprev-3d

    poprev-3d

    Joined:
    Apr 12, 2019
    Posts:
    71
    Thanks ! That also works perfectly for me !
     
  22. Blepius

    Blepius

    Joined:
    Mar 9, 2021
    Posts:
    68
    Hi all,

    InputSystem 1.4.1 and 1.4.2 are indeed both bonkers. There are the issues mentioned here and also I think some strange missed input issues as well. I didn't test for long because I noticed multiple issues and simply have no idea where to begin with things.

    If anyone forgot how to revert packages,
    1. Open the Package Manager
    2. click on the + icon
    3. Add package from GIT url...
    4. com.unity.inputsystem@1.3.0
    This did not work for me.
     
  23. Riptide559

    Riptide559

    Joined:
    Feb 1, 2020
    Posts:
    9
    This worked for me also. Thank you!
     
  24. Riptide559

    Riptide559

    Joined:
    Feb 1, 2020
    Posts:
    9
    They should care as it results in many developers wasting hours (which equates to money) tracking down whether this is a real issue or not. If I see errors, I first assume I didn't implement something correctly.
     
  25. Burgrokash

    Burgrokash

    Joined:
    Sep 12, 2018
    Posts:
    9

    Thanks! This did the trick for me :D
     
  26. Forberg

    Forberg

    Joined:
    Oct 27, 2018
    Posts:
    25
    Had a similar problem with the OnDisable errors popping up. Additionally one of the actions stopped firing events (Composite Action of WASD) after disabling and re-enabling its associated Action Map - unsure whether these errors are related, but both started occuring at the same time

    Was all resolved by reverting to 1.3.0.

    Thanks @Catsploration for the suggestion!
     
    FIFTYTWO likes this.
  27. FIFTYTWO

    FIFTYTWO

    Joined:
    Oct 21, 2014
    Posts:
    49
    There is an issue with composite actions after upgrading to 1.4.x. We noticed that the same composites in different action maps are conflict to each other. Let's say you have an UI action map with WASD composite to navigate UI elements and a gameplay action map with WASD composite to move a character. In this case UI handles all input but gameplay receives nothing. We can't disable UI action map because we have intractable UI overlay which is active during gameplay. I'm not sure if this issue is related to the errors on exit play mode but these two issues came together.
     
    Last edited: Oct 18, 2022
    MuntyMcFly likes this.
  28. MontblackJJ

    MontblackJJ

    Joined:
    Jul 22, 2020
    Posts:
    5
    I have the same problem by reloading the Scene (
    SceneManager.LoadScene(SceneManager.GetActiveScene().name, LoadSceneMode.Single) )
    , I tried all the suggested solutions, Lucky I'm just started with the new Input system so my solution is getting back to the classic Unity Input.
     
  29. rabblerousy

    rabblerousy

    Joined:
    Mar 9, 2020
    Posts:
    4
    Bjornicus, Alvarden, pdinklag and 2 others like this.
  30. kirimikh2008

    kirimikh2008

    Joined:
    Dec 18, 2022
    Posts:
    2
    What version of unity do you have?
     
  31. kirimikh2008

    kirimikh2008

    Joined:
    Dec 18, 2022
    Posts:
    2
  32. Jobberson

    Jobberson

    Joined:
    Apr 27, 2023
    Posts:
    1
    The last update fixed it for me, the Input System 1.5.1. There's no errors anymore