30

I have installed the new InputSystem package in my Unity project. I have set the input to "new inputsystem" in the Unity Player Settings. I have quit and restarted both Unity and VS Code.

But when I try to use the system in VS Code, I immediately get this error:

using UnityEngine;
using System.Collections;
using UnityEngine.InputSystem;              // <-error
using UnityEngine.InputSystem.Controls;     // <-error

The type or namespace name 'InputSystem' does not exist in the namespace 'UnityEngine' (are you missing an assembly reference?) [Assembly-CSharp]

What can I do to make VS Code recognise the Unity InputSystem package?

3
  • Are you sure you want "InputSystem", or you want UnityEngine.Input?
    – Lotan
    Commented Aug 28, 2020 at 15:59
  • Did this help? forum.unity.com/threads/…
    – Injourn
    Commented Aug 28, 2020 at 17:53
  • Yes, InputSystem (the new one). That thread helps, but the issue keeps reappearing. It's so annoying!
    – Kokodoko
    Commented Aug 28, 2020 at 19:11

13 Answers 13

58

The issue is that the required .csproj files (VSCode needs them to understand the available libraries) for the new package were not auto-generated when you installed the new package (it didn't happen for me either, maybe it is intentionally manual).

Go to Edit -> Preferences... and then click on External Tools. You need to tick the box to Generate .csproj files for: Registry packages (and any other ones you might want) and then click on Regenerate project files.

Screenshot from Unity's Preferences dialog

That should generate whatever is needed for VSCode to recognize the new package - you shouldn't even need to restart it.

6
  • 3
    Work perfectly - thank you. I didn't even need to restart VS Code
    – Flippi
    Commented Feb 18, 2021 at 4:35
  • 3
    @Flippi - It seems you are right, I also didn't need the restart. Updated the answer
    – anula
    Commented Feb 18, 2021 at 7:58
  • works like a charm (had to add multiple other packages as well tho ... but in general, very helpful answer. Thank you)
    – StyleZ
    Commented Nov 2, 2021 at 21:56
  • 3
    This will only work if the dependencies are actually there to be resolved. If regenerating does nothing for you, make sure to install the Input System from the package manager first.
    – Pfinnn
    Commented Dec 15, 2021 at 19:03
  • @Pfinnn The question explicitly mentions that the package is already installed.
    – anula
    Commented Dec 30, 2021 at 15:03
24

There's multiple reasons for this issue

I had an existing Assembly Definition that needed an Assembly Definition Reference to Unity.InputSystem

Assembly Definition in Project view

I added an Assembly Definition Reference to Unity.InputSystem in the inspector for "Scripts"

Assembly Definition in inspector, with Unity.InputSystem referenced

Rebuild had 0 errors.

3
  • If you have written tests before, you must do this step because writing and running tests require you to have an Assembly Definition Reference
    – Narc0t1CYM
    Commented Oct 30, 2022 at 12:59
  • I want to add for those with the same problem that some of the starting templates of Unity use Assembly Definition References. For example, the karting game starting template has an Assembly Definition Reference in Assets > Karting > Scripts > AI > Karting Game.AI. You have to add the Unity.InputSystem Definition to this in the list of references for it to work.
    – Tovi7
    Commented Nov 27, 2022 at 19:27
  • I had imported assets which had files *.RUNTIME that I needed to do this for!!!
    – jacobian
    Commented Mar 18, 2023 at 0:42
18

You need to install the package. Go to Windows / Package Manager. Search Input system and press install confirm to restart and replace the old input system.

2
  • 6
    I did that :) I mention that in my question :) But it did help to restart several times and set the player settings manually. Somehow the dialog that asks if you want to switch to the new system never shows up.
    – Kokodoko
    Commented Aug 29, 2020 at 9:37
  • This helped me. I thought changing it in the Player Settings would be enough.
    – Tim MB
    Commented Jul 22, 2022 at 15:04
13

If you get errors when Unity is trying to resolve the dependencies for the new Input System.Follow these steps and it should work: Regenerating your project only works, if you have the Input System actually installed.

  1. Install Input System (Windows > Package Manager)

enter image description here

  1. Set your project to new Input System (Project Settings > Player > Input System)

enter image description here

  1. Regenerate Project Files

Like other answers suggested, try regenerating your project files. This will only work, if the previous steps were succesful.

enter image description here

6

Select your Input Action Asset, and turn on Generate C# Class from the inspector window and click on apply to generate a C# script file.

1
  • 1
    After trying all the above. This is the part I was lacking - good tip. Weird it's not on by default?! Commented Jan 20, 2023 at 16:14
4

I had the same issue (Mac 10.15.17 with Unity 2019.3.151f1 personal) but the above didn't work 100% for me. Here was my solution:

First, I ensured that I installed the InputSystem package via the package manager. Window > Package Manager. Search for it and you should be able to install 1.0.2 which is the newest as of this post.

From there, I ensured that VS code was setup correctly. I when to Unity > Preferences > External Editor and ensured that VS code was the correct editor. I then selected Regenerate project files.

Lastly, on the script I was using, I included it in the top of the file like so:

using UnityEngine;
using UnityEngine.InputSystem;
0

close the Unity and VB, remove these files from the project folder *.sln *.csproj , run unity then click Assets -> open C# project

0

Solution:
Go to Edit -> Preferences... and then click on External Tools. Remove the tick from the box for: Registry packages (and any other ones you might want) and then click on Regenerate project files.
I don't know why but it worked for me (no need to restart VS Code)
Image of the steps
Environment:
Unity version: 2020.2.7f1
VS Code version: 1.61.2
Input System Package version: 1.2.4

2
  • This actually worked for me! Although it doesn't make much sense it seems to fix some underlying bug. Commented Jan 17, 2022 at 15:52
  • 1
    @einUsername see?! that's why I mentioned "I don't know why but it worked" and yet I got negative vote :)
    – No.BoD
    Commented Jan 20, 2022 at 7:02
0

I did all the above and still had the problem. What finally, helped me was:

Changing VS Code package to 1.2.3. You can do that by going to:

Packages/Manifest.json

finding:

"com.unity.ide.vscode"

and changing version from "1.2.4" to "1.2.3"

The original solution was posted by user Cartina: https://forum.unity.com/threads/cannot-find-unityengine-inputsystem.807645/

-1

I came across the same issue, and solved it. so, leaving a note here.

my case

In my case, after installing the new InputSystem package by Package Manger on Unity Editor, and then restarting Unity Editor following the appeared dialog, I could see Input System under Packages folder on Project view. However, any reference to namespece UnityEngine.InputSystem got errors.

What I found that Unity.InputSystem.dll didn't exist under [Project Dir]/Library/ScriptAssemblies/Unity.InputSystem.dll, which is what the Unity project refers to. This path can be found in Assembly-CSharp.csproj, placed right under Unity project directory.

Actually, it was not only for Input System package but also the same for all the other packages I uses. [Project Dir]/Library/ScriptAssemblies only had 2 files, Assembly-CSharp.dll and Assembly-CSharp.pdb, although this directory should hold dll files from all the installed packages.

solution

My solution was simple.

  1. delete Assembly-CSharp.csproj file ( to be regenerated at some stage )
  2. close Unity Editor
  3. close Unity Hub
  4. open Unity Hub
  5. open Unity Editor

At the last step, before Unity Editor fully waked up, I could see all the package dll files are loaded to [Project Dir]/Library/ScriptAssemblies directory.

I'm not so sure whether csproj file delete and Unity Hub restart was necessary, but this is what I did, which recovered my broken project.

my environment

  • Unity 2019.4.14f1
  • macOS 10.15.7
  • Visual Studio 8.8.4
1
  • 1
    deleting Assembly-CSharp.csproj is just enough.
    – Gaston
    Commented Oct 11, 2021 at 16:12
-1

In my case (Windows, Unity 2019.4 15f1, Visual Studio Code 1.53.0, Input System 1.0.2) Setting the Architecture of the project to x86_64 helped.

File-> Build Settings -> Plattform (PC, MAC & Linux Standalone)

I'm not sure though if this could even effect VS Code or if I did anything else in between to resolve this.

-1

if you wanna Using Something Like inputField Or Etc. you can do it by add

using UnityEngine.UI;
-1

In my case I was creating my Script in a third-party folder (Mirror). As soon as I moved it to my Scripts folder it worked.

Not the answer you're looking for? Browse other questions tagged or ask your own question.