How to Implement NetworkManagers? (cross-posted from Stack Overflow)

I’m fairly new to Unity, and very new to networking concepts. I’m trying to attach a NetworkManager script containing a custom OnServerAddPlayer function to an empty game object with a NetworkManager game component. However, when I attempt to do this, I receive a “the script class cannot be found… …ensure the file name and script class match” error.

My research has suggested vaguely that perhaps only MonoBehaviour scripts can be attached to GameObjects (?), but I haven’t been able to find anything explicitly stating this anywhere. And if one can’t attach NetworkManager scripts to GameObjects, how would one reference variables on the NetworkManager component like startPositions and spawnPrefabs? And does the script need to be attached to a GameObject for

public override OnServerAddPlayer (NetworkConnection conn, short playerControllerId) {…}

to be called?

Then allow me to confirm it. Scripts have to inherit from MonoBehaviour to be attached to GameObjects. The wording used in the documentation is that “MonoBehaviour is the base class from which every Unity script derives”.

That said this isn’t the problem here because NetworkManager itself inherits from MonoBehaviour. You can see this near the top of the docs entry under the name of the class.

https://docs.unity3d.com/ScriptReference/Networking.NetworkManager.html

From the error you’re getting it sounds like a simple name mismatch. The name of the class and the name of the file must match and keep in mind Unity is case sensitive. Any capital letters used in the class name must be exactly the same in the file name.

Thank you! Name mismatch was indeed the problem, and I was got so sidetracked by confusing myself that I completely missed it. Problem is fixed now!