- Home /
Unet error code : unity host id out of bound id -1 max id should be greater 0 and less than 2
Tried to run on 2018.2.0f2 and 2017.2.0f3 That's now 3 days I'm trying to get rid of this error. I've tried to allow unity in my firewalls, uninstall and install back again unity, to see if i've modified something wrong. But I can't even see what the issue is. Here is the complete error :
unity host id out of bound id {-1} max id should be greater {0} and less than {2} UnityEngine.Networking.NetworkDiscovery:Update()
and here is the code I us for the NetworkManager and the NetworkDiscovery :
NetworkManager :
public bool runAsServer = true;
private CustomNetworkDiscovery netDiscovery;
void Start () {
netDiscovery = GetComponent<CustomNetworkDiscovery>();
netDiscovery.Initialize();
if (runAsServer) {
SetupServer();
} else {
SetupClient();
}
}
void netDiscovery_OnReceivedNetworkBroadcast(string fromAddress, string data)
{
Debug.Log("Received fromAddress:" + fromAddress);
Debug.Log("Received data:" + data);
networkAddress = fromAddress;
StartClient();
netDiscovery.StopBroadcast();
}
void SetupServer(){
networkAddress = "localhost";
StartHost();
netDiscovery.StartAsServer();
}
void SetupClient(){
netDiscovery.OnReceivedNetworkBroadcast += netDiscovery_OnReceivedNetworkBroadcast;
netDiscovery.StartAsClient();
}
override public void OnClientDisconnect(NetworkConnection conn)
{
base.OnClientConnect(conn);
StopClient();
enabled = false;
netDiscovery.enabled = false;
Invoke("ProcessDisconnect", 0.5f);
}
void ProcessDisconnect()
{
enabled = true;
netDiscovery.enabled = true;
netDiscovery.Initialize();
netDiscovery.StartAsClient();
}
NetworkDiscovery :
public delegate void BroadcastEvent(string fromAddress, string data);
public event BroadcastEvent OnReceivedNetworkBroadcast = delegate { };
override public void OnReceivedBroadcast(string fromAddress, string data)
{
OnReceivedNetworkBroadcast(fromAddress, data);
}
I've tried to run it on 2018.2.0f2 and 2017.2.0f3
this is beyond weird. the Sourcecode is free to view on bitbucket and the first statement in the NetworkDiscovery's Update is a return when hostID is -1. no debugs or anything.
I can't help here, never had that problem with my network projects but I never ever used that component not good I override it...
Answer by Fattie · Oct 08, 2018 at 09:17 PM
Regarding this infuriating problem caused by Unity's shoddy network code.
Just on your PCs/Macs, check you are getting good internet connection (ie, can you get to ordinary web sites fast)
Ensure that in the Unity project, you have "run in background" on
Often it will work "one way and not the other way". Swap around your two PCs/Macs as client/server .. and it will work the other way. Really stupid and infuriating.
And for late 2018 Unity introduced a new problem:
on that essay carefully note the "aside" added in RED - that will fix the problem in many cases. Infuriating!
Your answer
![](https://koobas.hobune.stream/wayback/20220612171608im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
TextMesh multiplayer/network issue 0 Answers
Unity not recognizing my scripts 0 Answers
[C#]CalcHeight issues 1 Answer
Cannot use Network Transform Child in unity 2019.1of2 3 Answers
Netcode not working on Quest 1 Answer