Why my custom network script automatically adds a NetworkIdentity component every time I add it to my NetworkManager object?

Hi there,

I’m updating the network code of a videogame I was creating using the previous networking solution and I’m finding this issue:

Every time I add my script NetworkControl.cs to my gameObject NetworkManager it automatically adds a NetworkIdentity component which shouldn’t be there, as far as I understand.

Why could this be happening? When I add other scripts to the same gameObject, there’s no NetworkIdentity component that gets immediately attached to the very same object. It only happens with this one. What is more, no matter what gameObject I attach this script to, it will always automatically generate a NetworkManager component and a NetworkIdentity component, but I don’t want the NetworkIdentity component in there at all (I read here that NetworkIdentity component should never be in the same object as the NetworkManager).

My network script simply has a public NetworkManager variable which I link to the NetworkManager component of that object by using classic GetComponent() and then I just access all unet functions from there.

My NetworkControl.cs script looks a bit like this:

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Networking;
        
[AddComponentMenu("Network/NetworkManagerHUD")]
[RequireComponent(typeof(NetworkManager))]
        [System.ComponentModel.EditorBrowsable(System.ComponentModel.EditorBrowsableState.Never)]
public class NetworkCtrl : NetworkBehaviour
{
        public NetworkManager nmanager;
        
    	void Awake()
    	{
    		// set new network manager
    		nmanager = GetComponent<NetworkManager> ();
    
    		PlayerPrefs.SetString (UPID, unetID.ToString());
    	}
}

(I’m skipping the rest of the code because is not related to the network set up itself and it’s just a crazy mixed madness of good old RPCs and ClientRPCs/Commands but I’d say the problem is definitely not there as most of that code is simply commented out).

When running the game, I get the following error message:

"NetworkManager has a NetworkIdentity component. This will cause the NetworkManager object to be disabled, so it is not recommended.
UnityEditor.NetworkScenePostProcess:OnPostProcessScene()"

Best,

Pzeronov

because NetworkCtrl derives from NetworkBehaviour instead of MonoBehaviour