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
Answer by seanr · Dec 21, 2015 at 05:02 PM
because NetworkCtrl derives from NetworkBehaviour instead of MonoBehaviour
Thanks a lot. That was it. I had changed that at some point when I wasn't sure how unet works to test some stuff and by changing it back to $$anonymous$$onoBehaviour everything went back to normal.
I found this at the top of Google --
Currently, you add a Network$$anonymous$$anager via a "Network$$anonymous$$anager" component.
However, if you also have a Lobby$$anonymous$$anager, you get this error and your lobbymgr poofs away.
This is built-into Unity so you can't just "remove" the NetworkBehavior. So... what do you do?
Your answer
Follow this Question
Related Questions
Lerping to Smooth Network Movement 0 Answers
UNET - How to wait for NetworkConnection.Send(...) to finish? 0 Answers
UNET (Multiplayer) calling [command] function twice 0 Answers
Command function called on server 0 Answers
What does this error mean? 1 Answer