Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Visual Studio Code - UnityEngine: Unnecessary using directive.

Discussion in 'Editor & General Support' started by MilesAway1980, Mar 1, 2020.

  1. MilesAway1980

    MilesAway1980

    Joined:
    Oct 11, 2014
    Posts:
    13
    Hi all,
    I'm having an issue with Visual Studio Code.

    ALL of my scripts are suddenly saying: `UnityEngine: Unnecessary using directive.`

    Then, all of my scripts are littered with errors, due to everything related to Unity saying `The type or namespace X cannot be found`. Such as MonoBehaviour, GameObject, Camera, etc.


    However, all of the scripts compile and there are no actual errors when running the project. So, this seems to be some disconnect between VS Code and Unity. It seems to strictly be on VS Code's side. The issue is, I didn't change anything. It just suddenly happened a few days ago, and I haven't been able to get rid of it. I've shut everything down, restarted, tried other projects, etc. and it's all the same. A sea of red "errors" in VS Code.

    Unity Hub, Unity, and VS Code are all up to date, as well as all of the associated Unity plugins and VS Code extensions.

    Any ideas?
     
    Last edited: Mar 2, 2020
  2. CyrusJ

    CyrusJ

    Joined:
    Dec 17, 2019
    Posts:
    2
    Im having this too, Did you fix it?
     
    FunFreighterGames likes this.
  3. FunFreighterGames

    FunFreighterGames

    Joined:
    Aug 9, 2013
    Posts:
    8
    I'm having this issue as well, but I can't run the project
     
  4. FunFreighterGames

    FunFreighterGames

    Joined:
    Aug 9, 2013
    Posts:
    8
    It seems like I got it to work by 1. deleting the library 2. deleting csproj files in the root project folder 2. opening unity and adding variables using the previously problematic namespaces 3. restarting unity and vs. I don't know if all these steps were necessary or what the heck is happening but that's what I did.
     
  5. CharlieCook

    CharlieCook

    Joined:
    May 10, 2019
    Posts:
    13
    Had this problem. Closed VS 2019, and then I added a new c# script: Test_Script.
    Ran Test_Script.cs , and that fixed it.
     
  6. hosstyle

    hosstyle

    Joined:
    Feb 4, 2020
    Posts:
    1
    I can confirm that this solved it for me. Just create a new script in Unity, open it up by double clicking in the Project, problem fixed in Visual Studio. I originally opened the script in Unity from the Inspector (instead of the Project), and I also upgraded to a new version of Unity, so those may be factors to why this happened.
     
  7. Tj_W

    Tj_W

    Joined:
    Oct 15, 2019
    Posts:
    1
    This works! Thank you :)
     
  8. endererolreotek

    endererolreotek

    Joined:
    Mar 28, 2022
    Posts:
    4
    thats worked for me. Thanks for the help hoss.

    I think this is a bug.
     
  9. Rawd

    Rawd

    Joined:
    Jun 21, 2016
    Posts:
    3
    This also worked for me. Thanks!