Reputation: 28148
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?
Upvotes: 32
Views: 71765
Reputation: 13
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/
Upvotes: 0
Reputation: 572
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.
Like other answers suggested, try regenerating your project files. This will only work, if the previous steps were succesful.
Upvotes: 15
Reputation: 151
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
Upvotes: 0
Reputation: 737
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.
Upvotes: -1
Reputation: 828
There's multiple reasons for this issue
I had an existing Assembly Definition that needed an Assembly Definition Reference to Unity.InputSystem
I added an Assembly Definition Reference to Unity.InputSystem in the inspector for "Scripts"
Rebuild had 0 errors.
Upvotes: 27
Reputation: 13
if you wanna Using Something Like inputField Or Etc. you can do it by add
using UnityEngine.UI;
Upvotes: -1
Reputation: 39
close the Unity and VB, remove these files from the project folder *.sln *.csproj , run unity then click Assets -> open C# project
Upvotes: 0
Reputation: 4823
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;
Upvotes: 4
Reputation: 1047
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
.
That should generate whatever is needed for VSCode to recognize the new package - you shouldn't even need to restart it.
Upvotes: 60
Reputation: 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.
Upvotes: -1
Reputation: 1096
I came across the same issue, and solved it. so, leaving a note here.
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.
My solution was simple.
Assembly-CSharp.csproj
file ( to be regenerated at some stage )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.
Upvotes: -1
Reputation: 355
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.
Upvotes: 6
Reputation: 714
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.
Upvotes: 19