Author Topic: SGSK + TNET - LoadLevel  (Read 7882 times)

GregMeach

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 36
    • View Profile
SGSK + TNET - LoadLevel
« on: January 24, 2013, 11:37:42 AM »
Hello again,

I'm working on my jumpgate, script below:

  1. using UnityEngine;
  2. using TNet;
  3.  
  4. public class Jumpgate : MonoBehaviour {
  5.        
  6.         public GameObject jumpTarget;
  7.        
  8.         void OnTriggerEnter ( Collider other )
  9.         {
  10.                 Debug.Log("Entered gate to: " + jumpTarget.name);
  11.                 if ( jumpTarget != null) TNManager.LoadLevel(jumpTarget.name);
  12.         }
  13.        
  14. }
  15.  

When I launch the game from the Welcome Screen (with networking) it just stops upon entering my jumpgate cube. It works fine if I run from any other level (no networking). In both cases I see my Debug.Log in the console.
  1. Entered gate to: Thulane
  2. UnityEngine.Debug:Log(Object)
  3. Jumpgate:OnTriggerEnter(Collider) (at Assets/MeachWare/Scripts/Jumpgate.cs:11)
  4.  

On each jumpgate object (cube) I also dropped in the TNObject script so they each have an ID.

What did I miss???

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #1 on: January 24, 2013, 11:42:42 AM »
TNManager.LoadLevel call forces a level load on every single player in the same channel. I am guessing you want it wrapped in an if (TNManager.isHosting). If connected, LoadLevel call will send a packet to the server (RequestLoadLevel), and the server will respond (ResponseLoadLevel). Make sure that happens for you.

GregMeach

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 36
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #2 on: January 24, 2013, 12:47:04 PM »
AH.... thanks... that may/may not be what I want.

Looking over the example TNet, I revised Jumpgate.cs to:
  1. public class Jumpgate : MonoBehaviour {
  2.        
  3.         public GameObject jumpTarget;
  4.         public int jumpChannel;
  5.        
  6.         void OnTriggerEnter ( Collider other )
  7.         {
  8.                 Debug.Log("Entered gate to: " + jumpTarget.name);
  9.                 if ( jumpTarget != null) TNManager.JoinChannel(jumpChannel, jumpTarget.name);
  10.  
  11.                 //Application.LoadLevel(jumpTarget.name);
  12.                 //TNManager.LoadLevel(jumpTarget.name);
  13.         }
  14.        
  15. }

Now it is working perfect!!! Okay, not really perfect since it's all herky-jerky but that's what transitions are for ;-)

In addition, each waypoint will have it's own channel and save file (right?). Sorry, headed back to the documentation page, need to soak this up.

Thanks for the super quick response - I rated all 3 packages on the asset store as 5-stars and will leave a review once I'm more up to speed.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #3 on: January 24, 2013, 01:00:10 PM »
Yup, that is exactly the way to do it. :)

GregMeach

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 36
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #4 on: January 24, 2013, 02:09:10 PM »
Sorry.... I'm being super needy....  ;)

I was soooo close...

Here are my scene's:
Welcome -> Loads Tutorial on channel 100
Tutorial has jump gate to Level1, channel 101
Level 1 has jump gate to Level2, channel 102
Level2 has jump gate to Level 3, channel 103
Level3 has jump gate back to Level1, channel 101

When I cycle around and get back to Level1 it continuously spawns new player ships and repeats the jump gate Debug.Log's (in order) until I stop. In looking over the documentation if my player (the only one) leaves the channel, does the channel AND the scene stay in memory unless I send a RequestCloseChannel?

I'm really sorry to keep bugging you with what are most likely n00b-ish errors but I'm hoping in a few minutes you can steer me in the right direction.

Thanks and is there a way to get notified when you reply got it under options....

Edit:
If I close the channel just before I join the new channel it seems to work.
Updated Jumpgate.cs
  1. using UnityEngine;
  2. using System.Collections;
  3. using TNet;
  4.  
  5. public class Jumpgate : MonoBehaviour {
  6.        
  7.         public GameObject jumpTarget;
  8.         public int jumpChannel;
  9.        
  10.         void Start ()
  11.         {
  12.         }
  13.        
  14.         void OnTriggerEnter (Collider col)
  15.         {
  16.                 Debug.Log("Entered gate to: " + jumpTarget.name);
  17.                 if ( jumpTarget != null && jumpChannel >= 0 ) {
  18.                         //TNManager.LeaveChannel(); //didn't fix looping error
  19.  
  20.                         TNManager.BeginSend(Packet.RequestCloseChannel); // DID fix looping error
  21.                         TNManager.EndSend();
  22.                        
  23.                         TNManager.JoinChannel(jumpChannel, jumpTarget.name);
  24.                 }
  25.         }
  26. }
  27.  

If this the "proper" way then I'll design my game around this. Seems like I'll use a "GalaxyManager" class to manage systems (scenes) and then when each system (scene) loads it will read its update from the manager.
« Last Edit: January 24, 2013, 04:57:15 PM by GregMeach »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #5 on: January 24, 2013, 06:22:17 PM »
I'm guessing you are forgetting to destroy the player object before leaving the scene. TNManager.Destroy(playerObject), then proceed with JoinChannel.

You will also want to add this logic to the host as well -- when you get a player left notification, for any reason, make sure that the player's avatar has been removed.

GregMeach

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 36
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #6 on: January 25, 2013, 04:15:06 PM »
Thank-you for the reply.

Did I miss a readme (read the txt file) or informational post about the SGSK? I really do want (& need) to understand it so I can properly alter it to suit my games design. (and so I can stop bothering you with these questions).  8)

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #7 on: January 25, 2013, 10:07:52 PM »
I never did any formal writeup for SGSK. It's just a starter kit with all the documentation being in comments (in code). TNet and NGUI are the only ones with a decent writeup. HUDText too, but it's really simple anyway.

GregMeach

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 36
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #8 on: January 26, 2013, 09:50:52 AM »
Okay, cool - thanks again and those comments do help!

I was about to ask why the TNObject.id was defined as an int but in other methods it was an uint (uint makes more sense) and I read this:
  1.         /// <summary>
  2.         /// Unique Network Identifier. All TNObjects have them and is how messages arrive at the correct destination.
  3.         /// The ID is supposed to be a 'uint', but Unity is not able to serialize 'uint' types. Sigh.
  4.         /// </summary>
  5.  
:) thanks

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #9 on: January 27, 2013, 02:25:50 AM »
I've unified all usages of this in the latest version (1.3.1).

GregMeach

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 36
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #10 on: January 27, 2013, 05:06:36 AM »
Cool, that's for TNet, right? Pretty sure I have v1.3 now

Can we update the combined SGSK package or will you email us an updated link?

Thank-you!

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #11 on: January 27, 2013, 05:16:30 AM »
Just grab the TNet's update from the asset store.

GregMeach

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 36
    • View Profile
Re: SGSK + TNET - LoadLevel
« Reply #12 on: March 29, 2013, 09:53:46 AM »
Just grab the TNet's update from the asset store.

Just to confirm, to update your combined (TNet & NGUI) Space Game Starter kit, just delete either the TNet or NGUI folders and re-import the new one from the asset store. I just updated mine and it worked fine... Of course you should still test it on a backup copy ;)