Why unityengine.ui is not recognized? - unity3d

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:

You Could try a 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 the 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;

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.

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.

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).

These steps covered several possible issues:
https://stackoverflow.com/a/70977258/6046022
(just an overview, follow the link for the complete steps)
downgrade VSC package
re-install Unity UI
regenerate files

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

Related

VS Code cant find references to some Unity Classes

So, i just upgraded my Visual Studio Code Package from 1.2.3 to 1.2.4 and then it cant find the references to Cinemachine, UI and TextMeshPro anymore. With any other code editor it works well, even with Visual Studio 2019.I'm using Unity 2021.1.3f, and i cant find were to downgrade the version of the VS Code package.
Use the Unity Package Manager window (in Unity’s top menu: Window > Package Manager) to view which packages are available for installation or already installed in your project. In addition, you can use this window to install, remove, or update packages for each project.
Ok, so i found a solution, but its kinda weird and i hope they fix it by the next unity update.
for Unity 2021.1.3f1
First you need to create another Unity project. The VS Code package already come in the 1.2.3 version from default.
Close Unity after the project is created.
After that you need to copy the "Assets" folder and the "Project Settings" folder to your new project. Unfortunatly you have to manually install any package that you project depends on manually (Because i dont know how to copy/paste any package from one project to another) and after that dont update the VS Code package again.
I higly recomend creating a copy of your project (or having it in a git repository) before updating any package because Unity dont let you downgrade packages anymore.

VSCode: Attempted to update project that is not loaded

I am using VSC for Unity v2019.4. I have the package from package manager installed. Also I have installed dotnet. The thing is that when I open VSC (through Unity) it shows in the output:
Attempted to update project that is not loaded: C:\workspaces\Unity\MyGame\Assembly-CSharp.csproj.
am able to use the editor, but the Intellisense is not working. I also have tried to change the omnisharp version to latest and it is still not working.
You can try a few things in order to make Visual Studio Code works properly with Unity.
First of all make sure that the editor package is installed in your project via Package Manager. Latest version should be installed.
Just to be sure it's better to close the project, delete Library folder and all .csproj and .sln files.
Then you can open your project in Unity again, wait it to load and try to remember to open scripts not by double clicking, but instead use right click in Project window and select Open C# Project. This will load the scripts without any issues.
In case anyone is still having this problem, try to install .net framework 4.7.1
Try uninstalling then reinstalling vs code and dotnet latest version. Also make sure vs code is installed in a folder with permissions to edit. If not it will not save any files until you run as admin

Can not start a new project as unity has "failed to load window layout"

Clicking "load default layout" does nothing (just rerenders the alert box), clicking "revert factory settings" also does nothing.
I've googled this issue and the common solution is to reopen unity and to reimport all assests except this is a brand new project. There is nothing in it to import.
I've tried creating a new project and it still gives me this error.
I'm running version 2020.1.5f1 and the target platform is Windows 64-bit
Quit Unity and do the following:
Go to "AppData\Roaming\Unity\Editor-5.x\Preferences\Layouts\default" or "~/Library/Preferences/Unity/Editor-5.x/Layouts/default" for mac, delete LastLayout.dwlt and copy Default.wlt
Paste Default.wlt into the "Library" folder of your project
Delete CurrentLayout-default.dwlt and rename Default.wlt to CurrentLayout-default.dwlt
Reopen Unity and load the project. The editor should open normally. You should now be able to create new projects as usual too.
the simple solution if it has yet to be tried would be to uninstall unity and reinstall.
if you have already tried that try updating to a newer version see if unity 2020.3 works to narrow the problem down a bit more. I had the same problem for me I just updated unity to a newer version and everything worked perfectly.
I tried the solutions posted by #carmelo343 and #Abhishek Dubey, but it still didn't work. My solution was to create the unity project using an older version (I used 2019.3.12f1), which shouldn't cause that layout error, then change the unity version to 2020.1.5f1 in Unity Hub (see below)
Unity Hub
go to "C:\Users<username>\AppData\Roaming\Unity\Editor-5.x\Preferences\Layouts\default"
Copy this file in your project library folder renaming it with "CurrentLayout-default.dwlt" and replace it with the old one.
Worked for me!!
I get this most every time I launch a project in Unity. Then I close and relaunch and all is fine. I am using a personal layout. I am using Unity 2020.1.8f1. These kind of things never happened before 2020 version.
just try this : in unity editor: Help -> Check For Updates -> uncheck the Check For Update
On Windows:
Open your project folder and delete the CurrentLayout-default.dwlt file
Go to "C:\Users<username>\AppData\Roaming\Unity\Editor-5.x\Preferences\Layouts"
Copy Default.wlt file to your project library folder and rename it to "CurrentLayout-default.dwlt"
my project opened normally without the warning.
I solved this by downloading and installing the latest Unity Hub.
I saved my project to a different location and was able to open Unity.

Visual studio Intellisense color-coding not working for unity script editing [duplicate]

When I want to edit C# Unity scripts, they open in Visual Studio. It is supposed to provide auto complete for all Unity related code, but it doesn't work.
Here you can see the missing functionality:
As seen, the transform object does not open the autocomplete menu.
Unity version: 5.5.2f1
Visual studio 2015
Visual Studio Tools for Unity is installed
There is no auto-completion because the script says "Miscellaneous Files" instead of the of the name of the Project. Take a look at the image below that came from the video in your question:
The "Miscellaneous Files" message can happen for many reasons:
It can happen when you open your Unity C# file from another folder instead of opening it from Unity Editor.
This can also happen because Unity crashed while Visual Studio is still open therefore corrupting some files.
It can happen because Unity was closed then re-opened but is no longer connected to Visual Studio. When Visual Studio is opened you get "Miscellaneous Files" and no auto-completion.
This can happen when Visual Studio Tools for unity is not installed.
When you create a script from Unity then quickly open it before Unity finish processing it or before the round icon animation stuff finish animating.
Most of the times, restarting Unity and Visual Studio should fix this.
I can't tell which one is causing the problem but I will cover the most likely solution to fix this.
Fix Part 1:
Download and Install Visual Studio Tools for unity from this link. Do this while Unity and Visual Studio are both closed.
From Unity Editor, go to Edit → Preferences... → External Tools. On the External Script Editor drop down menu, change that to Visual Studio 2015.
Fix Part 2:
If newly created C# files are coming up as Miscellaneous then follow the instruction below:
From Visual Studio, go to Tools → Options... → Tools for Unity → Miscellaneous. Under Show connectivity icon, set it to true then restart Visual Studio.
When you re-start, connection icon should now be available in Visual Studio. Click it then choose the Unity instance to connect to. The red 'x' icon should now turn into a brown checkmark icon. Now, when you create a new C# file in Unity, it should open without saying Miscellaneous.
Fix Part 3:
Still not fixed?
Re-import project then open C# Project.
Close Visual Studio.
From Unity, re-import project by going to Assets → Reimport All.
Now, open the project in Visual Studio by going to Assets → Open C# Project. This will reload the project and fix possible solution file problems.
Fix Part 4:
Still not fixed?
Fix each C# file individually.
Click on Show All Files icon.
Select the script that doesn't do auto-complete then right-click and select Include In Project.
Fix Part 5:
Not fixed yet?
Credit goes to chrisvarnz for this particular solution which seems to have worked for multiple people.
Close Visual Studio
Go your project directory and delete all the generated Visual Studio files.
These are the files extensions to delete:
.csproj
.user
.sln
Example:
Let's say that the name of your Project is called Target_Shoot, these are what the files to delete should look like:
Target_Shoot.csproj
Target_Shoot.Editor.csproj
Target_Shoot.Editor.csproj.user
Target_Shoot.Player.csproj
Target_Shoot.Player.csproj.user
Target_Shoot.sln
Do not delete anything else.
Double click on the script again from Unity which should generate new Visual Studio file then open Visual Studio. This may solve your problem.
Fix Part 6:
If not working, check if you are having this error:
The "GetReferenceNearestTargetFrameworkTask" task was not found
Install Nuget PackageManager from here.
Restart Visual Studio.
See this answer for more information.
Fix Part 7
Make sure all of the projects are loaded.
In Solution Explorer it should tell you # of # projects.
If all of the projects are not showing, right click on "Solution (# of # projects)" and click Load Projects.
Try this,
In Unity Editor Go to Menu, Click on Edit -> Preferences -> External Tools -> External Script Editor. Set it to Visual Studio (your installed version of VS).
Now in Menubar go to Edit -> Project Settings -> Player Settings -> Other Settings -> Under Configuration -> Check API Compatibility Level -> Change it to your installed .Net version. In my case I set it to .Net 4.x
Now if Visual Studio is running already go to Visual Studio, it will ask to reload project. Reload the project. Check if it works, if not close Visual Studio. Now Open cs file from Unity Editor, and now it should work.
I found another way to fix this issue in a more convenient manner:
Select the broken file in Solution Explorer.
Open its Properties.
Switch field "Build Action" from "Compile" to "None".
Then switch it back to "Compile".
This will kill the synchronization between Unity and Visual Studio somehow.
The next time Visual Studio will reload the project, it will prompt a warning.
Just click on "Discard".
If you have done all of the above and still isn't working , just try this:
Note: you should have updated VS.
Goto Unity > edit> preference >External tools> external script editor.
Somehow for me I had not selected "visual studio" for external script editor and it was not working. As soon as i selected this and doubled clicked on c# file from unity it started working.
I hope it helps you too.
Unload and reload the project, in Visual Studio:
right click your project in Solution Explorer
select Unload Project
select Reload Project
Fixed!
I found this solution to work the best (easiest), having run into the problem multiple times.
Source: https://alexdunn.org/2017/04/26/xamarin-tips-fixing-the-highlighting-drop-in-your-xamarin-android-projects/
This page helped me fix the issue.
Fix for Unity disconnected from Visual Studio
In the Unity Editor, select the Edit > Preferences menu.
Select the External Tools tab on the left.
For External Script Editor, Choose the Visual Studio version you have.
Click regenerate Files
You Done
Select project in Visual Studio
Click "Refresh" button
I hit the same issues today using Visual Studio 2017 15.4.5 with Unity 2017.
I was able to fix the issue by right clicking on the project in Visual Studio and changing the target framework from 3.5 to 4.5.
Hope this helps anyone else in a similar scenario.
Two Alternative Options:
Fix 1
#singleton pointed me in this direction. Instead of changing the target in Visual Studio you should change it in Unity since the project is auto-generated.
First delete the auto generated Visual Studio files:
.csproj
.user
.sln
Then from within Unity go to PlayerSettings and under 'Other Settings' change the 'Scripting Runtime Version' from Stable 3.5 to Experimental 4.6.
However, that didn't fix it for me.
Fix 2
I noticed all of the references to Unity related code was marked with a yellow warning. Check your error logs and see if this is the case. In particular see if you get the following error: getreferenceNearestTargetframeworkTask
If so try:
Start Visual Studio Installer again.
On the Build Tools 2017, click Modify,
Ensure that "Nuget targets and build tasks" are ticked. This should become ticked if you click on Universal Windows Platform development.
Update 2020 with Visual Studio Community 2019 and Unity 2019.3:
Open Visual Studio Installer as Administrator, select to modify your current installation and add "Game development for Unity"
If you add a new c# script in Unity now, and open it (automatically) with Visual Studio, it is not described as "Miscellaneous" at the top of the window but with "Assembly-CSharp", and the autocomplete works.
i found my solution by creating the .cs file from visual studio itself instead of unity editor
right click on project folder in solution explorer
add > new item
type "unity" on the search field on the top right
select "CSharp MonoBehaviour"
name your script on the bottom and click Add
In my case, correct .net version was not installed on my PC. I install the .net 3.5 on my pc and that worked for me.
For Windows or macOS:
Download/Install the Visual Studio IDE (with Unity Tools)
When installing, make sure you include installation of
Game development with Unity
Then using Unity (you can double click one of your C# files), open a new C# project and the Visual Studio IDE should open with your new project structure.
From there, you should be able to see what you are looking for.
For example:
For Linux (suggestion):
Try Monodevelop - Additional Information, it provides code completion/hints.
My autocomplete also didn't work because Visual Studio Tools for Unity wasn't installed. So, after you install that, delete the auto generated Visual Studio files. Others said that you open file again and the problem is solved but it's not.
The trick is: instead of normally double-clicking the file, you need to open the C# file from Unity by right click and then "Open C# Project".
The issue I faced was that the C# Project was targeting a different .NET Framework (4.7.2), whereas the Unity project had a different target (.NET 3.5).
I fixed this by changing the target in Unity as-
File -> Build Settings -> Player Settings -> Other Settings -> API
Compatibility Level : Set it to the .NET version you already have
installed (Check your .NET Version here). In my case, it was 4.x
After this, Visual Studio worked perfectly and autocorrect was fixed too.
Try pressing Ctrl + Alt + Space (which toggles between suggestion and standard completion modes)
For some odd reason, the "Game development with Unity" tool can become disabled in Visual Studio.
To fix this..
Open Visual Studio
Go to Extensions → "Manage Extensions" → Installed
Find "Visual Studio 2019 Tools for Unity"
If it is disabled, enable it
Restart VS
Credit to Yuli Levtov's answer on another Thread
The following works for me.
Go to Edit->Preferences->External Tools->External Script Editor Select Scripting Editor
I solved to install the same version of .NET on WIN that was configured in my Unity project. (Player Settings)
Go to Options on the Tools menu and then select Documents in the Environment node. (If Documents does not appear in the list, select Show all settings in the Options dialog box.)
Put a tick on "Miscellaneous files in Solution Explorer" and Click OK. (This option displays the "Miscellaneous Files" node in Solution Explorer. Miscellaneous files are files that are not associated with a project or solution but can appear in Solution Explorer for your convenience if you tick this option.)
Locate your file in the Solution Explorer under "Miscellaneous Files". Then drag and drop your file to where it should belong and voila! This will copy the file to where you drop it. You may now safely delete the older file under Miscellaneous Files folder if you wish to do so
Credits: https://stackoverflow.com/a/47662523/10471480
In case Scripts folder is not visible:
Click on "Show all files" in Solution Explorer
Locate the Scripts folder.
Right Click on Scripts and select "Include in Project"
Keep in mind that if you are using the ReSharper tool, it will override the IntelliSense and show it's own. To change that, on VS, go to Extensions -> ReSharper -> Options -> IntelliSense -> General then choose Visual Studio and not ReSharper.
Before restarting and/or re-installing VS, First try opening any other of your projects to see if Intellisence works, if it does, then issue probably lies with your current project. First, most probable victim would be the NUGET packages with pending updates. To Fix this,
Right click on references
Proceed to Manage NUGET Packages Under NUGET Packages
proceed to updates Install Updates and recheck Intellisence
I tried all of these but ended up finding out that I needed to right-click the solution in Solution Explorer and add existing items and find the C# assembly file in Window's Explorer. There seem to be a bazillion different problems that give you this error, this is likely the most simple solution. If you double click on your script from unity, it does not seem to drag the assembly along.
Another possible fix:
In the project window, click on the Assets folder
Right click, and Create -> C# Script
Double click that, and wait.
For some reason, this work.
None of the above solutions worked for me. However I opened the ProjectName.CSPROJ file and manually added the new file and it worked like charm
What worked me is that I copied all the code inside the broken class and removed that file.
Then, I opened an empty file with the same name and pasted back.
Result: beautiful syntax highlights came back!
"Preferences" -> "External tools" -> set you exteranl tool
Thats one fix. Also for VS you can use ReSharper by JetBrains, but I recommend use Rider. That one is also free for students.
It provides less performance than visual studio, but more than VS+Resharper definitely.
Have a good day, mate)
Try with combination: Ctrl + Alt + Space
one of the above methods are worked for me and I just found a solution to this problem,
1. First, go to the project directory and delete .sln file
2. Second, go to unity and double click your script. Then Visual Studio will be open with an error,
Then click ok and close Visual Studio editor.
Finally, turn off your Windows Defender and then go to your project directory and there will be .csproj file. Just double click and open this from your Visual Studio editor and open the scripts folder inside the assets folder and open the scripts and autocompletion will be working perfectly fine.
These actions solved the problem for my projects in Visual Studio 2022
FIX 1
Solution
Assembly-CSharp (right-click)
Load Entire Dependency Tree
FIX 2
Solution
Assembly-CSharp
References
Double click on any lib to force loading

Reconciling BAR descriptors QNX IDE

Hello Everybody,
I am importing a sample project "Bucket-list" from Github https://github.com/blackberry/Cascades-Samples/tree/next/bucketlist in QNX IDE but not able to import successfully . Getting error .
Please have a look on Screen-Shoot and suggest me , what I will have to do for sort -out the issue.
All suggestions are welcome and appreciated
May be the issue is related to QNXIDE-Workspace setting , sometimes QNXIDE-Workspace setting changed ,Workspace setting reset is the most preferable solution in this way
I Follow some simple steps to sort-out the issue :-
1. Close QNX IDE
2. Remove .metadata folder that exist in BB10 Worspace
3. Restart QNX IDE & import the Sample project now it's compile & run fine
This happened to me after updating to the latest SDK. Applications worked properly before. Event clean projects "died" trying to compile BAR.
You can tell something is wrong by right clicking on the package, going to Properties, and selecting Actionscript Build Packaging > BlackBerry
To be clear, the instructions above about the .metadata folder is correct.
Open Explorer, go to C:\users\%username%\Adobe Flash Builder 4.7\
(orwhever the user folder is for your IDE) and rename the .metadata to old.metadata.
Restart IDE