Unity & VSCode not recognising Mirror despite being installed - c#

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

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 Scripts edited in Visual studio don't provide autocomplete on certain lines

When I edit the C# Unity Scripts, they open in Visual Studio. I've noticed that the autocomplete works on some lines but it doesn't in others.
Here you can see what's going on:
As you can see I get the autocomplete for GetComponent function only when I type inside the line 19.
I also tried this:
By moving the whole Start() function, autocomplete seems to work, but when moving back to the original place, it seems to stop working again.
By further testing, I noticed that autocomplete does not work on lines 11 through 14 and works on any other line.
I tried updating Visual Studio, deleting and recreating the C# Script, regenerated the project files and even reimporting all assets. Nothing worked.
Unity Version: 2020.2.7f1
Visual studio: 8.9.2
OS: macOS 11.2.3
Hm, that's strange. Try to go into the unity editor, go to edit/preferences/external Tools and select the VisualStudio version you are using as the external script-editor.

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 intellisense for Unity not working

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.

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.

Categories