Author Topic: Totally lost with what seems to be nothing working  (Read 4778 times)

thenick191

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Totally lost with what seems to be nothing working
« on: January 29, 2015, 01:21:23 PM »
So I'm working on a game that was previously built on Unity Networking. The game starts in a menu, goes to a load screen then to a level. Transitions between levels go to the load screen and then to the next level. Players are supposed to be able to go from their game at any point and join someone else's. I have an in game cheat to connect to a different server. I tell it to stop running the server, connect to the other server using internal/external ip, on connection success to server then join the channel. Nothing that was made using Create gets created and the server player doesn't even get the notification that a player joined. The connect to server is a success too.
I have a Lobby Server on digital ocean and in code I tell the game server to start.

I have absolutely no idea what I'm doing wrong. I would greatly appreciate any tips you can give me.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Totally lost with what seems to be nothing working
« Reply #1 on: January 29, 2015, 01:35:10 PM »
Most often this is result of not waiting on proper callbacks.

OnNetworkConnect is sent out when the connection gets established, for example. Some people call Connect() then immediately start on game logic, not realizing that Connect() is a delayed call. Same with others. When you Disconnect() you need to wait for OnNetworkDisconnect() before doing anything. Joining a channel too -- you must wait for OnNetworkConnect, do the join channel operation, then wait for OnNetworkJoinChannel.

thenick191

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Totally lost with what seems to be nothing working
« Reply #2 on: January 29, 2015, 02:21:39 PM »
So it appears that OnNetworkDisconnect is never actually happening. I've been having an issue with the broadcasts not actually working, so I set TNManager.client.onDisconnect = OnNetworkDisconnect where OnNetworkDisconnect is the method on the current script. I am calling TNServerInstance.Stop(), but nothing happens. In fact, I then check what servers are active in the Lobby List and the local one is still there. I think I must be missing some fundamental knowledge of TNet.

Knightmare

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 8
    • View Profile
Re: Totally lost with what seems to be nothing working
« Reply #3 on: January 29, 2015, 09:47:30 PM »
Yeah, sounds like the issue Aren pointed out. I had the same issue when starting out with TNet. Waiting for the callbacks are the key. I would say it might be that you are not in a channel even when you make the proper calls or possibly the script that handles the OnNetworkDisconect is not active or never was. As I do exactly how you assume it should be happening as you explained above and it works fine and my server stops. I have a personal State Manager and a Messenger that handles this, not sure how Aren does his but there are several ways to go about it.

thenick191

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Totally lost with what seems to be nothing working
« Reply #4 on: January 29, 2015, 10:42:12 PM »
I'm confused that the methods don't get called though because his broadcast literally pulls in every monobehaviour in the scene and checks if the method exists. I even put a Debug Log in the method that calls Broadcast and that wasn't getting called either.

thenick191

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 25
    • View Profile
Re: Totally lost with what seems to be nothing working
« Reply #5 on: January 30, 2015, 10:59:43 AM »
I think I figured out the key point I was missing. I totally did not realize at first that the player that starts a server actually then has to connect to it. I was assuming it worked like Unity's did for me that if I started a server the hosting player auto connected. I'm going to try this and let's see what happens :)