Issue with VSCode and Unity snippets

I just started the C# for Unity (2D) course and I’ve encountered a problem in VSCode
when trying to input: float steerSpeed = Input.GetAxis("Horizontal");
VSCode doesn’t recognize the Input class or the GetAxis method - meaning it doesn’t show up as an autocomplete option, nor does the code work in general when running the game in Unity
I’ve tried reinstalling the recommended extensions, rewriting the script, and I don’t know what to do anymore

MacBookPro running Sonoma 14.1.1 - Unity 2021.1.28 - VSCode 1.85.0

1 Like

Welcome to the community!

  1. Make sure you have this:
    float steerSpeed;

Somewhere above your line that is causing your error

Also having
using UnityEngine;
At the very top line, but I assume that you never took that out.

If this is not related to code, try these steps:

  1. Restart vscode
  2. This discussion might help:

If not, I may be misunderstanding your question, is this a code based issue? Then please copy your code from the script that’s causing the issue. Is this a question related to the connection between vscode and unity?

1 Like

Thank you!

my issue is that when I type in the Input.GetAxis part, vscode doesn’t show either the Input nor the GetAxis in the auto-complete drop-down menu, and then consequently the code doesn’t work as intended
the video I am following does not have float steerSpeed; declared on a separate line before the one I mentioned earlier, it has the declaration and initialization all in one line

I made sure I have using UnityEngine;

is there some way to make sure I have the UnityEngine lib on my device?

1 Like

Oh yeah I didn’t see the float in the beginning of your error, my bad!

Anyways, I found a step by step guide that could help:

If Visual Studio Code is not recognizing the Input class or the GetAxis method, and you’ve already ensured that your script includes the necessary using UnityEngine; statement, there might be an issue with the Unity Tools for Visual Studio Code.

Here are some additional steps you can take:

Restart Visual Studio Code:
Close Visual Studio Code and reopen it. This ensures that any changes or extensions you’ve installed take effect.

Unity Debugger Extension:
Open Unity Preferences in Visual Studio Code (Cmd + ,), and ensure that the “Unity Debugger” is selected.

Reinstall C# Extension:
Try uninstalling and reinstalling the C# extension for Visual Studio Code. You can do this from the Extensions view (Ctrl+Shift+X).

Check Unity Project Settings:
Verify that your Unity project settings are configured properly. Go to Edit > Project Settings > Player and ensure that the “Api Compatibility Level” is set to “.NET Standard 2.0” or “.NET 4.x Equivalent.”

Update Unity and VSCode:
Ensure that you are using compatible versions of Unity and Visual Studio Code. Sometimes, updating Unity and Visual Studio Code to the latest versions can resolve compatibility issues.

Check for Errors in VSCode Output:
Look for error messages or warnings in the Output tab in Visual Studio Code. This may provide more information about why the autocomplete is not working.

In Unity, the necessary libraries, including UnityEngine, are typically part of the Unity Editor installation, and you don’t need to separately install them on your device. However, you can perform a few checks to ensure that everything is set up correctly:

Unity Installation:
Ensure that you have Unity Hub installed, and you’ve installed a version of Unity that includes the modules you need. Unity should automatically include the necessary libraries like UnityEngine.

Project Folder Structure:
Make sure that your Unity project has a proper folder structure. Unity scripts should be placed within the Assets folder. If your script is not recognized, it might be in the wrong location.

Library Folder:
Unity generates a Library folder within your project. This folder contains various cached data and assemblies. Ensure that this folder is present in your Unity project directory.

Reimport All Assets:
In the Unity Editor, try selecting Assets > Reimport All to force Unity to refresh and reimport assets. This can help ensure that any missing or corrupted files are updated.

Check .csproj File:
Open the .csproj file associated with your Unity project and verify that it includes the necessary references, including .

Unity Preferences in VSCode:
Ensure that you have the correct Unity version selected in the Unity Preferences in Visual Studio Code (Cmd + ,). Also, make sure the “Unity Debugger” is selected.

Clean and Rebuild:
In Unity, try selecting Assets > Open C# Project to open the C# project files in Visual Studio Code. Then, try rebuilding the project using the Visual Studio Code command palette (Ctrl + Shift + P > “Clean Solution” and “Rebuild Solution”).

This is what I managed to find, hope this helps!

1 Like

Thank you for the comprehensive reply

I double checked all the settings you mentioned and they are correct (as per your instructions)
I have also tried uninstalling and reinstalling all of the related software and extensions to no avail
I have also asked for assistance on the Discord server and it seems that they recommend not using vscode anymore, but the alternative they recommend is PC only and I am on mac, do you have any recommendations on that front perhaps?

1 Like

Maybe take a look at the discussion post I linked in the beginning, it seems that some people don’t have issues when they use vscode community edition rather than the basic one, that might play a role, nothing related to your computer type I would think.

1 Like

I was shown the solution on discord, thank you again for your help!

for visibility I followed this link

I downloaded the extension as well as updated the relevant packages in Unity’s package manager window (under the Window drop-down menu), and now it all works

1 Like

Nice, I’m glad your issue worked out, good luck on your game dev journey!

Also please mark the post that solved your problem as the “solution” so others that get the same issue can easily solve their problems.

Nicely done!

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms