Project lost all references to Unity dlls
Hi, all of sudden my project lost all references to the Unity dlls. In the script the "using UnityEngine;" directive says "type or namespace name 'UnityEngine' cannot be found (are you missing a using directive or assembly reference". The reference to UnityEngine.dll is in the project references, though it has a yellow triangle on it (along with a number of others).
Things I have tried:
1) Deleting Library folder and restarting Unity.
2) Deleting the .csproj and .sln files (Unity doesn't regenerate them when I open a script afterwards)
3) Uninstalling then reinstalling Unity.
4) Changing the project to the .NET 4.x framework (previously was 3.5)
5) Changing the API Compatibility Level to 4.x (previously was 2.0)
6) I can't manually add references, when I right-click the project, and go to "Add", "Add Reference" is not an option.
7) I can't edit the reference itself, the path is blank and grayed out.
I didn't upgrade Unity, it was working fine one day, and the next day it was just broken. And it's nothing to do with git or other version control (not using them. yeah yeah, yell at me about that some other time...). Don't know what else the problem could be.
I also can't access the project Properties in VS. When I right-click the project -> Properties, there's just a flash like it opens then immediately closes.
I started a new project and it has the same problem. This has to be a bug. It completely hoses EVERYTHING.
Also tried adding a Plugins folder and directly pasting UnityEngine.dll into it. It created a .meta file, but nothing else. Even deleted the UnityEngine reference in VS and reloaded Unity/VS, still no dice.
Where's your project located? maybe you stored it in a problematic location that gives you issues with permissions or readonly settings? Also make sure you do NOT start Unity with ad$$anonymous$$istrator rights. This creates much more issues than it may seem to solve.
Apart from that the VS project is completely irrelevant for Unity. It's only there for convenience inside your code editor (Visual Studio). I'm not saying that is doesn't matter since it's annoying when code completion doesn't work. However there's nothing we can do about your issues. There are just too many potential things that could go wrong on your side. In almost all cases where people said "something suddenly happend" they just didn't pay attention to what they actually did which caused the issue. Often it might be something see$$anonymous$$gly unrelated (installing / updating antivirus software, moving the project from one location to another, ...)
Answer by mattmsty · Oct 22, 2020 at 04:42 AM
This happened to me after the latest update. I fixed my issue by opening Assembly-CSharp.csproj with a text editor, and manually fixing the hintpaths. For some reason, they didn't update when I updated my project.
For example, I had to change:
<HintPath>C:\Program Files\ **2019.3.14f1** \Editor\Data\Managed\UnityEngine\UnityEngine.dll</HintPath>
to:
<HintPath>C:\Program Files\ **2020.1.10f1** \Editor\Data\Managed\UnityEngine\UnityEngine.dll</HintPath>
Answer by rosssssss · Jul 29, 2019 at 04:18 PM
This happened to me and it turned out that i had accidentally created a new "Assembly Definition" in the assets somewhere (in my case amongst the scripts.) Deleting this accidentally made thing and everything went back to normal hurray.
Answer by ImperialDynamics · Jul 15, 2020 at 08:15 AM
it happens from time to time. Noone knows why. It's by faaar the single most annoying thing about Unity. Your project works fine. You turn off your PC, the following day you open the exact same project unmodified and Unity throws hundreds of errors. If anyone in Unity reads this forums we'd like to have an explanation AND A LONG-OVERDUE FIX!!!
Answer by lodendsg · Jan 25, 2021 at 11:12 AM
This is still an issue with Unity We have seen this various times in the past, this most recent time it was an upgrade from 2020.2.1f to 2020.2.2f.
For us the quickest way to fix it is to remove all the csproj and sln files then try to open a script. Unity should see its missing and rebuild them.
I sware there used to be a button in the Edit menu for Rebuild Solution files ... or maybe that was something we created.
@Unity This issue has been a intermitent issue for years. Its usually trivail to fix if your comfortable with VS and Unity but for many this is the point they threw Unity out in favor of UE or something else. Please fixing this should be as simple as on start up or double click of a script to start proc VS confirming the references of the projects are correct for the version of the editor your runing.
PS: a better forum would be nice to :) I shouldn't have to type <br>
to add some minor white space.
Your answer
Follow this Question
Related Questions
Why I get a generate error? 1 Answer
MS SQL Database and System.Data dll 2 Answers
How do I set up 5DT gloves in Unity 5.4.1? 1 Answer
C/C++ Dll not found while installing APK in HMT-1 device 0 Answers