Unity scripts don't work: "Script class cannot be found" - c#

Hello everybody,
A few days ago, a new error showed up on my computer: Unity scripts don't work at all. Every time I try to open (new or old) Unity projects, 2 blank errors appear (first screenshot), and when I try to attach a script to a GameObject, and alert dialog box shows (second screenshot). You can also see in the script import settings: "No MonoBehaviour scripts in the file or their names do not match the file name"...
I already tried to uninstall all Unity's related files, reinstall it, uninstall and reinstall Virtual Studio 2019 and SDKs, so if you have an idea of where it could come from, just tell me!
Thanks a lot,
Simon

The problem you're facing is called "Blank Error". Looking for Blank Error Unity you'll find many possible solutions.
For instance:
https://forum.unity.com/threads/four-blank-errors-in-each-new-project.599980/
What fixed it for me was to "install windows update from this link to your 32 bit or 64 bit system accordingly":
https://support.microsoft.com/en-us/help/2533623/microsoft-security-advisory-insecure-library-loading-could-allow-remot

Ok, so I installed MSVC v140 and v141, Unity 2018.4.13f1 and it seems to work now, after this I tried with Unity 2019.2.15f1, and I think there is an error with this version, I had the same problem.
But right now I can use Unity, that's what I wanted, thanks for all people who helped me !

Related

Compilation error when creating new project in Unity

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.

Unity VSCode autocomplete Intellisense not working

I've downloaded VSCode as an IDE for Unity including the extensions unity Debugger and Unity code snippets. The editor shows me suggentions like awake() or start() methods but no variables like Rigidbody, transform or input. How can i solve this problem?
I´ve had the same problem. Only switching to Visual Studio (and downloading the Unity extension) solved it for me.
My Colleagues first recommended Code to me too, but in the end I didn´t see the benefit in it.
In Unity Edit -> Preferences -> External Tools -> Select your external script editor
Still having troubles?
I answered a similar question here:
Visual Studio Code error when using unity
Also here:
How to get Visual Studio to recommend unity codes
You can install only one extension for Unity in VSCode.
unity3d-pack (1.0.0)
This package contains 10 packages in it and all sub-packages are useful for Unity programming.
C#
C# FixFormat
C# Snippets
C# XML Documentation Comments
Debugger for Unity
Shader languages support
Unity Code Snippets
Unity Tools
ShaderlabVSCode(Free)
Code Outline
I tried a few different quick-fix solutions, and none of them worked for me. I finally realized that there was a better way to debug this myself:
Open the Output panel in VSCode ("View -> Output" from the top menu)
Select "OmniSharp Log" from the drop-down in the top right of the Output panel
The problems were MUCH easier to debug once I could see the problems OmniSharp was having just trying to start up. Here were the problems on my Mac:
Somehow, the option "Omnisharp: Use Modern Net" was set to true. This is not supported by the Unity integration, so I had to unset it.
Even though dotnet was on my path, VSCode couldn't find it. I ran which dotnet in a terminal to find the path to the dotnet executable, and set the "Omnisharp: Dotnet Path" setting to that path.
Even though mono was on my path, VSCode couldn't find it. I ran which mono in a terminal to find the path to the mono executable, and set the "Omnisharp: Mono Path" setting to that path.

Visual Studio Code suddenly lost autocomplete with Unity

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.

Unity not generating necessary C# scripts for Visual Studio

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.

SpriteFont error in monogame on macOS "Microsoft.XNA.Framework.Content.ContentLoadException has been thrown The content file was not found."

I am trying to follow tutorials on monogame. using Xamarin studio 6.3 and Monogame content pipeline tool 3.6.
The error "Microsoft.XNA.Framework.Content.ContentLoadException has been thrown The content file was not found." keeps appearing. I have looked online and followed some advice, such as moving the font file from ~/Library/Fonts/ to /Library/Fonts/ and tried re-installing the programs. I'm not having any luck though. Always get the same error message.
I found a few posts such as the ones here: https://github.com/MonoGame/MonoGame/issues/5900
and here:
http://community.monogame.net/t/pipeline-fails-to-generate-spritefont/8204
but they say the issue is fixed?
I'm following this tutorial:
http://xnafan.net/2013/04/simple-platformer-game-in-xna-tutorial-part-five-improved-collision-detection/
Just to clarify, I know XNA and Monogame are different things and i've also been following a monogame tutorial here which also doesn't work.
http://rbwhitaker.wikidot.com/monogame-drawing-text-with-spritefonts
Everything is working fine up to the "Adding debug info to the game" section. I've tried several different tutorials incase something was missing from this one but no luck.
Any help or advice would be greatly appreciated :) Thank you
Nick.
Found a fix to the issue! If you download the developer version 3.7 and rebuild from the pipeline tool it works! The link to the dev version is here. download the whole thing as the pipeline tool is included.
http://teamcity.monogame.net/repository/download/MonoGame_PackageMacAndLinux/latest.lastSuccessful/MonoGame.pkg?guest=1
This is a problem a lot of people have that are new to MonoGame. The Content management system for MonoGame works completely different from XNA. The tutorial you're watching shows how to add content to an XNA game, not a MonoGame game. To add content to MonoGame, you need to open the file called Content.mgcb. This will bring you to a new window where you can add your content. Once you have added the content to Content.mgcb, you can save the file and use the Content. I will include step by step pictures to try and assist you in the process.
Step 1:
Find the Content.mgcb file and open it.
Step 2: Select the "Add Existing Item" button.
Step 3: Navigate to the file you wish to add. Select the item and click "Open".
I hope I was able to help.
Good luck,
- GHC

Categories