PTsag
PTsag

Reputation: 146

Why unityengine.ui is not recognized?

I have a problem were i try to create a score system in my game where the player is getting points based on the distance he travelled, and the vs code is not recognising the "Using UnityEngine.ui;" I already tried to switch vs code to a lower version (I went to 1.1.3) but it didn't work. Here is my code: enter image description here

Upvotes: 0

Views: 13748

Answers (6)

Suraj Bhandarkar
Suraj Bhandarkar

Reputation: 346

You could try a couple of solutions -

Solution 1) Relaunch the unity Engine and VS code and check.

Solution 2) Go to Edit > Preferences > External Tools make sure Edit > Preferences > External Tools make sure the

'Generate all .csproj files'

is checked then in your IDE delete the:

Assembly-CSharp-Editor.csproj

Assembly-CSharp.csproj

Ecology.sln files in the root of your project.

Close and reopen vscode.

Solution 3) Uninstall Unity Hub and reinstall again and try.

Solution 4) UnityEngine.UIElements; instead of unityEngine.UI;

Upvotes: 5

Phuc
Phuc

Reputation: 155

I have the same error what take me a lot of time to fix. And finally I found my reason that I meet a problem with duplicated extension in the same project. My one is "External Dependency Manager" what somehow installed already on Unity Package Manager, after I delete old Admob plugin and install new one what make install new "External Dependency Manager" without override or delete old one. That make Unity not work well.

So check and try to delete/uninstall "External Dependency Manager" in Unity Package Manager first then import new one will be fine. At least in my case

Hope this help

Upvotes: 0

Saleh Hosseini
Saleh Hosseini

Reputation: 523

These steps covered several possible issues:

https://stackoverflow.com/a/70977258/6046022

(just an overview, follow the link for the complete steps)

  1. downgrade VSC package
  2. re-install Unity UI
  3. regenerate files

Upvotes: 0

Drab1g
Drab1g

Reputation: 11

There seem to be a problem with the VScode package version 1.2.4, where regenerating csproj files from the preferences doesn't make Unity UI symbols available in vscode.

Going Back to version 1.2.3 solved the issue for me (from latest Unity 2020.3 LTS release).

Upvotes: 1

PTsag
PTsag

Reputation: 146

Well it seems that I already had ui tool installed so I tried to unistall the package and reinstall it. Vs code still throws an error sometimes but after I close it and open it again it works just fine. Thank you all for your help.

Upvotes: 1

vexaiv
vexaiv

Reputation: 190

UnityEngine.UI namespace is a part of the aditional package called Unity UI, and it seems you don't have it imported in the project.
Click on Window on the top-left menu in Unity Editor -> Select Package Manager -> Search for Unity UI -> click Install.

Upvotes: 3

Related Questions