Odd behaviour - Mirror imported, but not found

Hey all,

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 Networking successfully (can spawn in Player Objects, and they move over the network)

I’m getting issues when it comes to adding Public Overrides in a custom Network Manager script.

This is my code in my custom Network Manager Script (yes, this is it)

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 theUnity 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

When going through the first part of this course, I didn’t have any issues with this occurring at all, it’s only happened once moving to the actual “RTS” part of the course

Additionally, it seems that Visual Studio Code (or one of the extensions) is not working properly either. When replacing MonoBehaviour with NetworkManager, this should throw an error in VSCode which prompts me to add using Mirror; - this doesn’t appear at all.

When I start typing and the Predictive box comes up, this still only shows MonoBehaviour content, and nothing from Network Manager

What’s really odd is that I don’t get error CS0115 in the previous section’s 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

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
    • 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
    • VSCode Version: 1.67.2
    • Installed VSCode Extensions:
      • C# for Visual Studio Code
      • Debugger for Unity
      • GitLens
      • PHP Intelephense
      • Unity Code Snippets

If anyone can figure out what’s going on here, that would be great - I’m pulling my hair out here!

Hi there,
First of all, I believe OnServerAddPlayer should have capital O at the beginning?

As for VSCode getting confused with classes, my usual debug list is the following.

  1. Install the VSCode package in the package manager in Unity, and make sure it is fully up to date.
  2. Make sure VSCode is also fully up to date including extensions.
  3. Close Unity, delete the Library folder, then reopen Unity and have it rebuild he Library folder temp files.

For Mirror, I find it sometimes has issues with updating existing scripts. So I general delete the entire Mirror folder before installing a new version of it.

Let me know if any of that helps, or if you require further assistance.

Hey - thanks for the help!

I had tried all the debugging in your list, and none of them had actually worked. Turns out the issue came from an update to the C# plugin for VSCode! I found this article on Stackoverflow which outlined the fix. A recent update to the extension broke the expected behaviour

1 Like

Hey! Glad you figured this out!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms