Author Topic: Clients disconnect when calling TNManager.LoadLevel(startLevel);  (Read 2359 times)

outerringz

  • Guest
I have a very basic test project setup with NGUI and TNet similar to the setup in the TNet video tutorial.

On the starting scene I have a TNManager script, and a Simple 2D UI with host, join, load level, and disconnect buttons with a DontDestroyOnLoad script on it.

Host OnClick calls:
  1. TNServerInstance.Start(tpc, upd);  // 5127, 5127
Join OnClick calls:
  1. TNManager.Connect(ip.text, Convert.ToInt32(port.text));  // local private IP, 5127
Load level OnClick calls:
  1. if (TNManager.isHosting) TNManager.LoadLevel(startLevel);
Disconnect OnClick calls:
  1. TNManager.Disconnect();
  2. if (TNManager.isHosting) TNServerInstance.Stop();

I also have an empty called Status with a NetworkStatus script on it that contains all the TNet built in notifications with debugs to help me see what's going on. The OnNetworkConnect event calls the following on success.
  1. TNManager.JoinChannel(channelID, null, false, 2, "");

If I start two instances, I click host then join on the first instance and the server is created and joined successfully. On the second instance, I click join and all is well. When I click load level from the server instance, both clients are disconnected from the server and redirected to the disconnect scene called during OnNetworkDisconnect().

I don't know why TNManager.LoadLevel is disconnecting the clients from the server.
« Last Edit: June 08, 2013, 04:00:14 PM by outerringz »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Clients disconnect when calling TNManager.LoadLevel(startLevel);
« Reply #1 on: June 08, 2013, 05:43:34 PM »
It certain'y shouldn't disconnect. Did you actually add this level to the build list?

Also, have you tried joining a channel with the level name already specified? It's the advised approach.

outerringz

  • Guest
Re: Clients disconnect when calling TNManager.LoadLevel(startLevel);
« Reply #2 on: June 08, 2013, 06:23:02 PM »
The scenes have been added to the build.

I'm currently joining the channel in the OnNetworkConnect event and using null for the level, then calling TNManager.LoadLevel(startLevel) from a Join button's OnClick. I prefer this method because I have multiplayer selections that need to take place before the next level is loaded.
  1. TNManager.JoinChannel(channelID, null, false, 2, "");
If I pass the level name instead, the level loads fine for client and server.
  1. TNManager.JoinChannel(channelID, "Game", false, 2, "");
But any call to TNManager.LoadLevel disconnects both clients.

Thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Clients disconnect when calling TNManager.LoadLevel(startLevel);
« Reply #3 on: June 08, 2013, 08:38:40 PM »
Here's what I just tried.

1. Launched the TNServer.exe.
2. Opened up the "Example AutoJoin" scene within TNet.
3. Selected the AutoJoin game object, and cleared the value of the "First Level" property in inspector.
4. Opened up Build Settings and moved "Example AutoJoin" to the top.
5. Created the following script and added it to the Main Camera:
  1. using UnityEngine;
  2.  
  3. public class Test : MonoBehaviour
  4. {
  5.         void Update ()
  6.         {
  7.                 if (Input.GetKeyDown(KeyCode.J))
  8.                 {
  9.                         TNManager.LoadLevel("Example AutoSync");
  10.                 }
  11.         }
  12. }
6. Built & ran the executable, then hit Play as well. Both clients connected.
7. Hit "J" on the first client. Both clients are now in "Example AutoSync" scene.

No disconnects.

Did you perhaps forget the very important "Run In Background" flag?

outerringz

  • Guest
Re: Clients disconnect when calling TNManager.LoadLevel(startLevel);
« Reply #4 on: June 08, 2013, 10:13:08 PM »
It was a stray script meant for another button that I missed somehow.

Thank you very much for your help, I'm sorry I wasted your time.