'RTSNetworkManager dot OnServerAddPlayer (NetworkConnection) ' method override

Hey there,

I am having the same sort of issue depicted in the topic Odd behaviour - Mirror imported, but not found
The compiler error we get is:
‘Assets\Scripts\Networking\RTSNetworkManager.cs(12,26): error CS0115: ‘RTSNetworkManager.OnServerAddPlayer(NetworkConnection)’: no suitable method found to override’

using System.Collections;
using System.Collections.Generic;

using UnityEngine;
using Mirror;


public class RTSNetworkManager : NetworkManager {
    
    [SerializeField] private GameObject unitSpawnerPrefab = null;

    public override void OnServerAddPlayer(NetworkConnection conn)
    {
        base.OnServerAddPlayer(conn);

        GameObject unitSpawnerInstance = Instantiate(unitSpawnerPrefab, conn.identity.transform.position, conn.identity.transform.rotation);

        NetworkServer.Spawn(unitSpawnerInstance, conn);
    }

Here is what VScode says when I hover the mouse over the red underlined ‘conn’:
Argument 1: cannot convert from ‘Mirror.NetworkConnection’ to ‘Mirror.NetworkConnectionToClient’ [Assembly-CSharp]csharp(CS1503)

I have followed all the steps Patrick_Hull took with troubleshooting. I will Paste that info here. Anything BOLD means a change from the original post:

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.32f1
  • VSCode Version: 1.68.1
    Installed VSCode Extensions:
  • C# for Visual Studio Code (ver. 1.25.0)
  • Debugger for Unity
  • GitLens
  • Unity Code Snippets

Patrick_Hull SOLUTION:

Here is the text from the thread answer in regards to using the C# for Visual Studio Code extension version 1.25.0:
.NET Framework builds of OmniSharp no longer ship with Mono or the MSBuild tooling (See announcement omnisharp-roslyn#2339). To ensure that the C# extension remains usable out of the box for .NET SDK projects, we have changed the default value of omnisharp.useModernNet to true.

If you still need Unity or .NET Framework support, you can set omnisharp.useModernNet to false in your VS Code settings and restart OmniSharp.

So I set my Vscode omniharp.useModernNet setting to false. Nothing has changed.
There is a second potential solution in the thread pointing to installing the dotNet SDK 6. I did this, but still no change.

I have yet to reformat my entire system, though I’d rather not have to resort to that. I’m not code savvy enough to create a workaround at this time. If anyone has any troubleshooting steps for me to jump through please let me know and I’ll report my findings.
Thank you for your time.

When I had this issue and changed the OmniSharp setting, for me initially it didn’t work - it took a couple of minutes for it to take effect.

I would set that OnmiSharp setting to false, and then just leave it for 10 minutes or so for it to take effect

I don’t believe you’ll need to reformat your system

One other thing I found was that NetworkConnection should be NetworkConnectionToClient - that should fix the conn error at least

EDIT: I don’t actually thing that OmniSharp is causing the error here. See how your first two “use” lines are kind of greyed out, and the next two are normal? That wasn’t happening for me at all, and that was fixed when OmniSharp was fixed. Try adding an update method, and see if VSCode auto suggests it

Hey Patrick

Thank you for your reply and guidance! Things seem to be working out now.

After making the post here I had walked away for some time. I had left the ‘useModernNet’ setting as false. That break probably gave Omnisharp enough space to do its thing for that 10 minutes you suggested above, allowing me to actually USE ‘NetworkConnectionToClient’.

During my initial research, I did find the documentation about the code depreciations for later versions of Mirror.

When changing the ‘NetworkConnection’ to ‘NetworkConnectionToClient’ (early in my research before posting) VsCode had thrown me additional squiggly red lines under ‘OnServerAddPlayer’ and likely something else… So I had immediately discarded any notion to use ‘NetworkConnectionToClient’ and forgot about it.

After reading your reply and replacing the wording this time around, there were no red lines, no errors. Everything compiled properly. I could even spawn in 2 players and roaming tanks in the application builds.

Patrick, thank you very much for replying to my post. I really believe letting omnisharp take its time get up and running allowed me to get the correct wording to compile.

The Greyed Out Lines:
I looked a little bit at the greyed out usingdeclarations at the top of my screenshot. It looks like C# says those two using declarations are unnecessary?
2022-06-19 21_21_29-Window

I’m not really sure if I should worry about it since everything is going smoothly now… I hope this helps though.

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

Privacy & Terms