Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by BMS-CB · Oct 01, 2015 at 12:12 AM · c#networkingerror message

Connection already ready when adding players to Host

Working on a game which will have three different game modes, two which are single device and a third which allows access through the network. In order to simplify the game code its been structured to have a single scene with networking identities on all relevant objects. In doing so, I'm setting up a custom NetworkLobbyManager which can be used regardless of game mode.

The error I'm seeing is when attempting to add local players, specifically Lobby Players, to a started host. The process flow is below:

 public class MyLobbyManager : NetworkLobbyManager {
     public void StartSingleHost() {
         maxConnections = 1;
         maxPlayers = 5;
         maxPlayersPerConnection = 5;
         autoCreatePlayer = false;
         StartHost();
     }
 }

This configures and starts the host. On the subsequent frame, I'm attempting to add two local device players via:

 MyLobbyManager lobbyMgr = FindObjectOfType<MyLobbyManager>();
 lobbyMgr.TryToAddPlayer();

This performs as expected; however Unity throws the error: "A connection has already been set as ready. There can only be one."

I've tried with several different approaches:

  • ClientScene.AddPlayer ~ Same error

  • NetworkServer.AddPlayerForConnection ~Different error, I don't recall the exact messaging

My original attempt is what is currently listed. After no results I used .NET Reflector to inspect how the NetworkLobbyManger had this setup. The key areas of interest in the NetworkLobbyManager are:

 public class NetworkLobbyManager : NetworkManager {
     public override void OnStartServer() {
         if (this.lobbySlots.Length == 0)
             this.lobbySlots = new NetworkLobbyPlayer[this.maxPlayers];
         this.OnLobbyStartServer();
     }
     public virtual void OnLobbyStartServer() {}
 
     public override void OnStartHost(){
         this.OnLobbyStartHost();
     }
     public virtual void OnLobbyStartHost() { }
 
     private void OnGUI() {
         ...
         this.TryToAddPlayer();
     }
 }

The reference I found regarding this issue showed that a simple check is being made to see if the connection already exists and then exists, with an error logged, if that is the case. As queried in the reference and based upon my own inspection, it doesn't look like this impacts anything; however, any errors in the log bother me. Inspecting further it does look as if StartHost() calls ConnectLocalClient() but tracing that is a veritable rats nest.

Is there a preferred method of starting a local host or connecting local players? Considering an implementation using a NetworkLobbyManager and the NetworkMangerHUD don't yield the same results when adding players I can't imagine this is a defect within Unity, unless there's something within the NetworkLobbyManager which is not available in the subclass. Now that I think of it, I did notice a similar, unresolved, issue when attempting to extend the NetworkLobbyPlayer.

Any insight into the matter would be greatly appreciated.

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by BMS-CB · Oct 02, 2015 at 03:00 PM

It looks like this may be a result of a delay between when the Host is started and the Client becomes ready. I had tried individual and successive calls to:

 if (ClientScene.ready) {
     ClientScene.AddPlayer(controllerId);
 }
 else {
     ClientScene.AddPlayer(NetworkClient.allClients[0].connection, controllerId);
 }

Always with the same error message. After moving on and trying to resolve another issue with stopping and restarting the Host, I noticed that the error was no longer occurring. Moving the player creation logic to the Update method resolved the error. More specifically, I threw it behind:

 public void Update() {
     if (!doneAddingPlayers && ClientScene.ready) {
         AddPlayer(controllerId);
         AddPlayer(controllerId);
         doneAddingPlayers = true;
     }
 }

I'll be doing some more inspection and if timing is the issue, creating a callback for player creation and adding that to MyLobbyManager once the client is ready.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image webgovernor · Jan 22, 2016 at 06:55 PM 1
Share

Hey, just wondering if the callback creation fixed your issue.

I'm also getting this error with the caveat that it ONLY happens if Network$$anonymous$$anager.Shutdown() was called at some point prior to visiting the scene with the Network$$anonymous$$anager.

For example, I enter the lobbyScene and call StartHost(), no issues. BUT, if I exit the lobby, kill the NetworkLobby$$anonymous$$anager instance, and call Network$$anonymous$$anager.Shutdown(), THEN I get the error (though it doesn't impact functionality in any way that I could see).

I've tried commenting out various overrides in the network lobby manager, but it didn't seem to make a different.

Thanks in advance.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Client can't spawn GameObject's 0 Answers

Multiplayer Moving Bullet 1 Answer

Unet error code : unity host id out of bound id -1 max id should be greater 0 and less than 2 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges