I recently downloaded Unity to mess around with game development for a class. After making and trying to run a new hello world C# script, Visual Studio promptly spat out about 70 errors saying that various C# scripts were not found. All of the errors looked something like this:
"[File not found] : C:/Users/njenk/Documents/Unity Projects/New Unity Project/Packages/com.unity.textmeshpro/scripts/'c#FileThatINeed'"
I did some digging into my new project's files to see if VS was correct. There are five folders VS reported missing C# scripts from, all of which are in the Package directory. Here's a photo for reference:
Package Directory
Every one of these folders was empty, not a single C# script to be found. VS is correct in saying it can't find anything. However, when I looked at my project in Unity's own file explorer, all of the 70 or so necessary C# scripts are present.
This seems very much like a case of VS not syncing correctly with Unity, but after several hours of looking online and messing around myself I came up empty handed. I found very few people with this type of error, so I am humbly request assistance from your end.
Related
I'm totally new in Unity and C#, and it's the first time I download Unity.
The problem I'm facing is: Evertime I try to create a totally new project or open an official example project should contain no error, the Unity will say that there are compilation errors in my project, just like the screenshot below:
Error pop-up
This situation will happen in any different version of Unity, I have tried these versions: 2021.3.14, 2020.3.42, 2020.3.25, 2019.4.40.
And the error messages in console of each version are different, in 2021.3.14:
Error message in console
(This kind of disorderly code should be Chinese I think, the reason maybe the Chinese encoded question in Unity. But I don't know why, because the Unity Hub and Unity I installed are all from UK website)
In 2020.3.42 and 2020.3.25:
Error message in console
And in 2019.4.40 the error message is just like the error message in 2020 version, just the "Compiler version 3.5.0-dev" changes to "Compiler version 2.9.1" (I don't have the screenshot cause I have deleted the 2019 version).
Here I'll explain the process I download and install Unity:
I just have an anaconda preinstalled in my computer(which is related to the Unity), and for the first time, I also have the Visual Studio2019 installed in my computer(But I try to uninstall VS2019 before install Unity later, it doesn't work). And I download and install the Unity Hub from official website, then install the Unity 2021.3.14 in Unity Hub. That's all the process, I didn't change anything else in the system about Unity. (There is actually one another thing I have done, but I don't think it's a reason. I download the ml-agents plugin in github, and created a new anaconda environment for it, with just python3.6 and pytorch and ml-agents installed. Then I try to add ml-agents in Unity's packages even it's in compilation error state.)
Here is some info about my computer:
UK computer with Windows11, with anaconda, some jdk and SQL installed.
And here is the list of things I have tried, all from internet:
Change the "Api Compatibility Level*" in Edit->Project Settings->Player->Other Settings->Configuration
Download different version of Unity(as mentioned above)
Delete some packages that may cause this problem
Reimport all the assets of the project
Delete the Unity_lic.ulf file in the directory: C:\ProgramData\Unity and let Unity reload it
Somebody says this may be caused by some antivirus program, so I removed all the antivirus program on my computer (except virus defense program of win11, cause I don't know how to close it and I think it is better to not close it), and completely remove all the Unity files on my computer (probably, I don't know), the remove steps are:
(1) Delete the Unity Editor and Unity Hub files directly
(2) Delete temporary file related to Unity:
C:\ProgramData\Unity
C:\Users\Username\AppData\Local\Unity
C:\Users\Username\AppData\Local\unityhub-updater
C:\Users\Username\AppData\LocalLow\Unity
C:\Users\Username\AppData\Roaming\Unity
C:\Users\Username\AppData\Roaming\UnityHub
(3) Remove all the Unity related folders in windows registry(to ensure the thing I'm saying, to open this, press win+R, then type"regedit"):
HKEY_CURRENT_USER\Software\Unity
HKEY_CURRENT_USER\Software\UnityTechnologie
And reinstall the whole Unity in a totally different directory, to avoid the Unity influenced by the folder path name(like too long, or contains Chinese character), I create a new folder F:\Unity, and create four folder"Download", "Editor", "Hub", "Project" to hold download tem files, Unity Editor, Unity Hub and project file respectively. Then I download and install Unity Hub, then install Unity Editor in Unity Hub, create new project, and everything don't change...
P.S. I also download a Unity use the same process as me on the computer of my roommate. His computer is also win11, with anaconda and Visual Studio preinstalled. And everything went right, it just took me several minutes to successfully create a new project.
Can someone tell me what kind of things can influence the download process of Unity (Like other programming environment or IDE)? And how can I fix this problem?
You tried every possible solution maybe it's time to reinstall a clean windows.
I'm getting some really odd behaviour in both Visual Studio Code and Unity, and I'm not sure where the issue is coming from, or how to fix.
I'm able to successfully import Mirror Components to Game Objects (i.e Default Network Manager), and am able to use Mirror successfully (can spawn in Player Objects, and they move over the network)
I'm getting issues when it comes to adding Public Overrides for Mirror in a custom Network Manager script.
This is my code in my custom Network Manager Script (yes, this is the whole script)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class RTSNetworkManager : NetworkManager
{
public override void onServerAddPlayer(NetworkConnection conn)
{
base.onServerAddPlayer(conn);
}
}
After typing this in, I get the following Compiler Error in the Unity Console:
Assets\Scripts\Networking\RTSNetworkManager.cs(8,26): error CS0115: 'RTSNetworkManager.onServerAddPlayer(NetworkConnection)': no suitable method found to override
When I remove the onServerAddPlayer function from this script, the script compiles successfully.
I'm going through a tutorial (GameDev.tv, intermediate C# Coding & Networking), and was working on another project in the same tutorial which also used Mirror, and this same script seemed to work perfectly fine
Additionally, it seems that Visual Studio Code (or one of the extensions installed) is not working properly either. When replacing the default MonoBehaviour with NetworkManager in the C# script, this should throw an error in VSCode which prompts me to add using Mirror; - this doesn't appear at all.
In general, when I start typing and the Predictive box comes up, this still only shows MonoBehaviour content, and nothing from NetworkManager
What's really odd is that I don't get error CS0115 in the previous project, however that project is now also affected by the VSCode glitches, which leads me to believe they are either Separate issues, or VSCode is the true culprit here
I also looked at this article here, but I suspect this is a different issue as Mirror is able to be used outside of VSCode
These are my troubleshooting steps:
Unity Error
Restarted Unity Editor
Restarted PC
Copied NetworkManager script from earlier section
Removed all .csproj files
Removed .sln files
Removed .vscode folder
Reimported Mirror
Removed project from PC and re-cloned from GitHub
Created new project from scratch
VSCode Error
Uninstalled relevant extensions (In bold below)
Reinstalled VSCode
Specs
Unity Version: 2020.3.26f1
I have also attempted on 2021.3.3f1
VSCode Version: 1.67.2
Installed VSCode Extensions:
C# for Visual Studio Code
Debugger for Unity
GitLens
PHP Intelephense
Unity Code Snippets
Any advice would be greatly appreciated - this is doing my head in!
EDIT 1
The error with Unity not recognising the Mirror has been solved (Thanks Retired Ninja!) - The VSCode Intellisense issue remains, which confirms that they are not related
I am currently learning AR Development by using Unity and Visual Studio Code on MacOS. I understand that part of the process is downloading the Mono.Framework in order to be able to use the autocompletion feature. That's what I did, but VS Code is throwing me an error: Unable to find Mono. Ensure that Mono's '/bin' folder is added to your environment's PATH variable.
Right now, I'm trying to edit my PATH variable which is
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands. I want to remove "/Commands" folder and replace it with the "/bin" folder.
So far, I've tried to re-start my computer, and when I open Unity and then a C# Script via Unity, it would work fine. I'd get the autocompletion to work with no problems. But when I close the Script and try to re-open it, I'd start getting the aforementioned error.
I tried to uninstall and reinstall Mono twice.
Also I t have tried is to add export PATH=/Library/Frameworks/Mono.framework/Versions/Current/bin:$PATH on my .bash_profile
The Expected Result result is this one:
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/bin
but the Result I get is this:
/Library/Frameworks/Mono.framework/Versions/Current/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/share/dotnet:~/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands
How can I change the "/Commands" folder and replace it with the "/bin" folder?
P.D. That is what I think is the best course of action in order to solve the error, but I'm totally open to be corrected in case I'm wrong.
More info:
MacOS - 12.1
Unity - 2021.1.9f1
VS Code - 1.56.2 (Universal)
Mono - 6.12.0.122
I have been programming on Unity with VSCode for the past two months and had very few issues about it. But suddenly, it has stopped the autocomplete, even thought I tried several approaches that I found online.
I have all the extensions needed for the development (C# (1.22), Debugger for Unity(2.7.5), Unity Code Snippets (1.3.0), Unity Tools (1.2.3) and am currently using Unity 2019.3.8f1 on Windows 10.
I have already changed the External Script Editor to work with VSCode but with no luck. I have also tried to delete all .csproj files, to restart computer/internet, all with no luck either
It says on my output panel that it is installing C# dependencies, but it never ends downloading them.
What is the possible cause of this problem ? I have found that many people have this kind of error, but they are always when trying to use VSCode with Unity for their first time. In my case I have been using for a long time and it has suddenly stopped.
Thanks in advance.
C# vscode extensions works by having the actual c# heavy lifting in a separate language server process "omnisharp.exe", and actual typescript extensions is mostly glue. So whenever c# extension gets updated, extensions manually downloads new version of omnisharp.exe.
As far as I know, all language services are turned off while new omnisharp.exe is downloading. Why your download is failing, I can't tell you really without more info, it could be something on your end.
I suggest you first try to uninstall/install c# extensions, as that may help if extension folder got corrupted in any way. If that doesn't help, try setting "omnisharp.path" vscode settings to "1.35.2" or "1.35.1" or similar, to manually target version.
so I've been trying to get Visual Studio Code set up to work with Unity.
Here is the list of extensions I have for Unity:
C# version 1.21.17
Debugger for Unity version 2.7.5
Unity Tools version 1.2.3
Unity Code Snippets version 1.3.0
So I have the IntelliSense working for methods like Awake, Start, OnCollisionEnter2D etc., but when I try to get methods like GetComponent they dont show up, which can be quite bothering as I am trying to learn and still dont know thte methods so well as to know all of their parameters and the exact way they are named.
So as it turns out(For some reason), the problem was that even though it appeared that when double clicking a script in Unity opened up the entire project folder in VS Code, I could see all the files and that stuff for some reason that was not properly loaded. I tried reopening the project folder from VS Code, rather than from unity and it all worked out. Now I am able to use IntelliSense to its full extent. Leaving this in case others are struggling with this.
Once you've opened up the project folder from vs code, if you leave it open, double clicking scripts from unity will work fine, no need to manually open thtem from vs code everytime you want to edit a script.
Sometimes it happens if you don't set VSCode as the default editor for Unity scripts.
In Unity go to Edit > Preferences > External Tools > External script editor and choose Visual Studio Code.