Author Topic: Problem with reconnecting (disconnect and connect again) to TNet server 3.0.1  (Read 3901 times)

kreibich

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
When I tried to connect to a TNet server, then disconnected and connected again (even when destroyed the GameObjects holding the TNet scripts after disconnecting), I'm not getting OnConnect feedback.

Video from Unity: https://www.youtube.com/watch?v=YftEJsympnw
Connection script attached below.

It seems like some static variables are not reset while reconnecting (TNManager.isPlaying)

Any advice?
Thanks.
« Last Edit: May 29, 2016, 09:18:49 AM by kreibich »

kreibich

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Solved - there is a bug in TNet 3.0.1 that does not reset TNManager.mDestroyed to false after disconnecting;

So I quickfixed it adding a new method in TNManager class:

public static void ResetVariables() {
   mDestroyed = false;
}

... and called it before connecting.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
mDestroyed is only set in TNManager.OnDestroy(), and since TNManager's game object is marked as DontDestroyOnLoad on creation, should only be called at the very end of the application's lifecycle.

Did you perhaps make a mistake of having TNManager be present in the scene on load, instead of letting TNet create it for you?

kreibich

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
I have TNManager script attached to an object in "Connecting" scene only (together with TNAutoJoin script as I saw it in one of your tutorial videos - https://www.youtube.com/watch?v=cTjy-L8C6WM)

I have 4 scenes:
- MENU - no TNet script on any object
- CONNECT - 1 object with TNManager and TNAutoJoin scripts on it
- GAME - One object with TNAutoCreate - there is attached Player object on it
- DISCONNECTED - no TNet script on any object

What do you mean by TNet will create it for me?
« Last Edit: May 29, 2016, 01:41:44 PM by kreibich »

Shifty Geezer

  • Full Member
  • ***
  • Thank You
  • -Given: 7
  • -Receive: 9
  • Posts: 226
    • View Profile
Don't add TNManager to any game objects. Just using TNet in your code has the management objects created for you and you reference them statically.

kreibich

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Well, then I'm doing it wrong, so is there any step-by-step video tutorial how to do it in new version? It seems that the video tutorial I mentioned above is probably obsolete (TNet v. 2.x?).

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
All tutorials are in a sticky post at the top of this forum, including an updated video tutorial.

http://www.tasharen.com/forum/index.php?topic=13953.0

kreibich

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Well it started working without TNManager instance now. I don't know what I exactly changed to make it work. But the problem with new connection remains.
« Last Edit: June 03, 2016, 09:02:03 PM by kreibich »

kreibich

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Now I've got just Empty GameObject called TNet and TNAutoJoin script attached to it. When I connect and then disconnect and connect again this TNet GameObject appears twice. That might be a problem. So I tried to destroy this object after disconnecting, but it did not helped, even that there is only one TNet GameObject now, it does not handle OnConnect event.

kreibich

  • Newbie
  • *
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 15
    • View Profile
Problem solved! I forgot these 2 lines in Disconnect method:

TNManager.onConnect -= OnConnect;
TNManager.onDisconnect -= OnDisconnect;