1

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

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • Looking at what I believe is the [documentation](https://mirror-networking.com/docs/api/Mirror.NetworkManager.html#Mirror_NetworkManager_OnServerAddPlayer_Mirror_NetworkConnectionToClient_) the signature is `public virtual void OnServerAddPlayer(NetworkConnectionToClient conn)` You have a lowercase `o` and a different parameter type. – Retired Ninja May 29 '22 at 04:49
  • That's solved the issues with the Unity Console error, thank you! I believe the other issue is to do with Intellisense, but other troubleshooting steps I've found (regenerating .csproj files, changing extension versions) doesn't seem to work – Patrick Hull May 29 '22 at 05:02
  • My answer here (https://stackoverflow.com/a/72404936/224734) may solve your issue with Intellisense. – frankhermes May 29 '22 at 12:33
  • Yes, that was it, thank you! I had tried that before, but I wasn't leaving enough time for the setting to apply. Took a while for it to take effect. Thank you! – Patrick Hull May 31 '22 at 10:47

0 Answers0