- Home /
uNet- A connection has already been set as ready. There can only be one.
I get this error when I try hosting a server using uNet's NetworkManager:
A connection has already been set as ready. There can only be one.
UnityEngine.Networking.NetworkManager:Update()
And I am not sure why. All I do is call StartHost() and then later call ClientScene.AddPlayer(0) to spawn a player.
Any idea why this happens?
I got this message when call Ready() method. By fact, the connection has already been ready and you should not do it again. By some mysterious reason it was called twice in your case. Not sure if it's the reason.
That's what I thought it might be, is I'm calling ready on clients - but when I do StartHost () as the client-server I don't call Ready (), only on clients who connect later... it seems to come from just calling StartHost ()?
Well, Network$$anonymous$$anager does it in its Update function until connection is ready and in OnClientConnect handler. In any case this error message does not seem so bad. There's the source:
if (ClientScene.s_IsReady)
{
if (LogFilter.logError)
Debug.LogError((object) "A connection has already been set as ready. There can only be one.");
return false;
}
I see. I wonder if doing ClientScene.AddPlayer() causes the network manager to try and set ready again?
And also I wonder if ignoring this error is fine?
Indeed... I still cannot handle a simple application: click to spawn an object. omg... P.S. You may use dotPeek disassembler (free software from jetbrains) to investigate issues like this.
Answer by Glabrezu · Jun 29, 2015 at 12:12 AM
I had this error when I extended NetworkManager. By trying to comment out various sections, I ended up finding what was causing it. Although I don't remember exactly what it was, I suppose this method would work for you, too.
Your right, I ended up switching over to NetworkLobby$$anonymous$$anager, and by changing the way I handled stuff I also avoided this error message. Wish I had something more constructive to add, but if anyone else hits this problem, look into your custom network manager!
Answer by DimKa_WG · Sep 21, 2015 at 12:55 PM
Hi. Think I figured out where is ClientScene.Ready()
or ClientScene.AddPlayer(0)
called second time.
It's OnClientSceneChanged()
method. Here is documentation, read the last sentence.
You can just override method and call in it your own code without calling base method.
If you're extending NetworkLobby$$anonymous$$anager, here's the code I needed to implement to work around the error. The only change from the NetworkLobby$$anonymous$$anager source code (as of 5.6) is commenting out the call to the base class.
public override void OnClientSceneChanged(NetworkConnection conn)
{
string loadedSceneName = Scene$$anonymous$$anager.GetSceneAt(0).name;
if (loadedSceneName == lobbyScene)
{
if (client.isConnected)
CallOnClientEnterLobby();
}
else
{
CallOnClientExitLobby();
}
/// This call is commented out since it causes a unet "A connection has already been set as ready. There can only be one." error.
/// $$anonymous$$ore info: http://answers.unity3d.com/questions/991552/unet-a-connection-has-already-been-set-as-ready-th.html
//base.OnClientSceneChanged(conn);
OnLobbyClientSceneChanged(conn);
}
void CallOnClientEnterLobby()
{
OnLobbyClientEnter();
foreach (var player in lobbySlots)
{
if (player == null)
continue;
player.readyToBegin = false;
player.OnClientEnterLobby();
}
}
void CallOnClientExitLobby()
{
OnLobbyClientExit();
foreach (var player in lobbySlots)
{
if (player == null)
continue;
player.OnClientExitLobby();
}
}
@Dim$$anonymous$$a_WG:
Unfortunately, I cannot confirm this. The [Documentation you've linked][1], especially the last sentence you're mentioning, seems to claim the contrary:You can just override method and call in it your own code without calling base method.
When I skip calling base.OnClientSceneChanged(...), no player instance will be added on my client at all, which breaks my game. Adding the base call again brings it back to work. In my understanding, this is why you can NOT skip the base method! [1]: https://docs.unity3d.com/ScriptReference/Networking.Network$$anonymous$$anager.OnClientSceneChanged.htmlThe default implementation of OnClientSceneChanged in the Network$$anonymous$$anager is to add a player object for the connection if no player object exists.
Answer by Anisoropos · Jul 28, 2015 at 08:41 PM
For me it was the fact that a Lobby Player's
SendReadyToBeginMessage();
triggers the Lobby Manager's
CheckReadyToBegin();
and if all Lobby Player flags (readyToBegin) are true, it tries to start the game.
If you call this more than once before the game starts, it will fail produce the following error:
A connection has already been set as ready. There can only be one.
UnityEngine.Networking.NetworkManager:Update()