Author Topic: RFC & RCC don't work when using null for joinChannel scene?  (Read 1118 times)

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
I don't want to load a new scene when players join their channel so I use NULL instead. But doing that seems to break RFC and RCC calls. Is this by design, a bug or am I missing something? 

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #1 on: July 01, 2017, 05:49:57 AM »
Missing something. Null / empty string as levelName is explicitly supported and you shouldn't experience any problems with RFCs or RCCs.

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #2 on: July 01, 2017, 11:51:27 AM »
I've attached two files that serve as a basic example of my approach. If I reload the same scene then it'll work fine:
TNManager.JoinChannel(1, "exampleScene",true,2,"");

All RFC calls in the tnetBehaviour script succeed.

But if I use null:
TNManager.JoinChannel(1, null,true,2,"");

then the RFC calls no longer reach the other player.

My workaround, at the moment, is to reload the same scene with a flag to indicate if it's a fresh scene load or a reload going into a multiplayer game.

tnetMultiplayer example file:
  1. using UnityEngine;
  2. using TNet;
  3. using System.IO;
  4. using System.Collections;
  5. using UnityTools = TNet.UnityTools;
  6.  
  7. [ExecuteInEditMode]
  8. public class tnetMultiplayerExample : TNEventReceiver {
  9.         //TNET variables start
  10.         static tnetMultiplayerExample mInst = null;
  11.  
  12.         public enum IPType
  13.         {
  14.                 IP_v_4,
  15.                 IP_v_6,
  16.         }
  17.         string serverName;
  18.         int knownServers;
  19.         public bool serverCrerated = false;
  20.         TNServerInstance ourServer;
  21.         public int serverTcpPort = 5127;
  22.         public IPType addressFamily = IPType.IP_v_4;
  23.         //TNET variables end
  24.  
  25.         //public string [] serverList;
  26.         public ServerList.Entry [] serverListInfo;
  27.         public ServerList.Entry myServer;
  28.  
  29.         public int totalServers;
  30.         public bool updatingList;
  31.         bool hosting = false;
  32.  
  33.         protected static tnetMultiplayerExample _instance;
  34.         public static tnetMultiplayerExample instance { get { return _instance; } }
  35.  
  36.         void Awake () {
  37.                 if (Application.isPlaying)
  38.                 {
  39.                         // Choose IPv6 or IPv4
  40.                         TcpProtocol.defaultListenerInterface = (addressFamily == IPType.IP_v_6) ? System.Net.IPAddress.IPv6Any : System.Net.IPAddress.Any;
  41.  
  42.                         // TNet will automatically switch UDP to IPv6 if TCP uses it, but you can specify an explicit one if you like
  43.                         //UdpProtocol.defaultNetworkInterface = useIPv6 ? System.Net.IPAddress.IPv6Any : System.Net.IPAddress.Any;
  44.  
  45.                         if (mInst == null)
  46.                         {
  47.                                 mInst = this;
  48.                                 DontDestroyOnLoad(gameObject);
  49.                         }
  50.                         else Destroy(gameObject);
  51.                 }
  52.         }
  53.  
  54.         void Start () {        
  55.                
  56.         }
  57.        
  58.         void Update () {
  59.                
  60.         }
  61.                
  62.         void OnEnable () {
  63.                 TNManager.onConnect += OnConnect;
  64.                 TNManager.onJoinChannel += OnJoinChannel;
  65.                 TNManager.onPlayerJoin += OnPlayerJoin;
  66.                 TNManager.onPlayerLeave += OnPlayerLeave;
  67.                 TNManager.onDisconnect += OnDisconnect;
  68.                 TNManager.onLeaveChannel += OnLeaveChannel;
  69.         }
  70.  
  71.         public void StartServer (string newServerName) {
  72.                 if (TNLobbyClient.knownServers.list.size > 0) { //check if an old server is still alive and kicking first
  73.                         //serverName
  74.                         for (int i = TNLobbyClient.knownServers.list.size - 1; i > -1; i--) {
  75.                                 if (TNLobbyClient.knownServers.list [i].name == serverName) {                                  
  76.                                         StartCoroutine (CheckForOldHostGame ());
  77.                                         Debug.Log ("OLD SERVER IS STILL ACTIVE!!!");
  78.                                         return;
  79.                                 }
  80.                         }
  81.                 }
  82.                 hosting = true;
  83.  
  84.                 int udpPort = Random.Range(10000, 40000);
  85.                 TNLobbyClient lobby = GetComponent<TNLobbyClient>();
  86.                 serverName = newServerName + "_" + (Random.Range(100000,900000)); //add a number to prevent duplicate server names;
  87.                 if (lobby == null)
  88.                 {                                              
  89.                         TNServerInstance.serverName = serverName;
  90.                         if (TNServerInstance.Start (serverTcpPort, udpPort, "server.dat")) {                           
  91.                                 TNManager.Connect ();
  92.                         }
  93.                 }
  94.                 else
  95.                 {
  96.                         TNServerInstance.serverName = serverName;
  97.                         TNServerInstance.Type type = (lobby is TNUdpLobbyClient) ?
  98.                         TNServerInstance.Type.Udp : TNServerInstance.Type.Tcp;
  99.  
  100.                         if (TNServerInstance.Start(serverTcpPort, udpPort, lobby.remotePort, "server.dat", type))
  101.                                 TNManager.Connect();
  102.                 }
  103.                 StartCoroutine (WaitForServerInit ()); 
  104.         }
  105.  
  106.         IEnumerator CheckForOldHostGame () {
  107.                 bool oldGameExists = true;
  108.                 float nextCheck = Time.time + 1;
  109.                 while (oldGameExists) {
  110.                         if (Time.time > nextCheck) {
  111.                                 if (TNLobbyClient.knownServers.list.size > 0) { //check if an old server is still alive and kicking first
  112.                                         oldGameExists = false;
  113.                                         for (int i = TNLobbyClient.knownServers.list.size - 1; i > -1; i--) {
  114.                                                 if (TNLobbyClient.knownServers.list [i].name == serverName) {
  115.                                                         oldGameExists = true;                                          
  116.                                                 }
  117.                                         }
  118.                                         if (!oldGameExists) {
  119.                                                 Debug.Log ("Old game is now gone");
  120.                                         }
  121.                                 } else { //no servers now. So move on
  122.                                         Debug.Log ("Old game is still active");
  123.                                         oldGameExists = false;
  124.                                 }
  125.                         }
  126.                         yield return new WaitForSeconds (1);
  127.                 }
  128.         }
  129.  
  130.         IEnumerator WaitForServerInit () {             
  131.                 List<ServerList.Entry> list = TNLobbyClient.knownServers.list;
  132.                 while (list.size == 0) {
  133.                         list = TNLobbyClient.knownServers.list;
  134.                         Debug.Log ("***List length:" + list.size);
  135.                         yield return new WaitForSeconds (1);
  136.                 }
  137.                 Debug.Log ("***we've got a list! "+TNLobbyClient.knownServers.list.size);
  138.  
  139.                 myServer = null;
  140.                 while (myServer == null) {
  141.                         GetListOfGames ();
  142.                         for (int i = serverListInfo.Length - 1; i > -1; i--) {                                         
  143.                                 if (serverListInfo [i].name == TNServerInstance.serverName) {
  144.                                         myServer = serverListInfo [i];
  145.                                         break;
  146.                                 }
  147.                         }
  148.                         yield return new WaitForSeconds (1);
  149.                 }
  150.  
  151.                 if (myServer.name != TNServerInstance.serverName) { //failed to find our server!
  152.                         Debug.Log ("***FAILED TO FIND OUR OWN SERVER!!!");
  153.                         //shut the server down and error out
  154.                 } else {
  155.                         TNManager.JoinChannel(1, "exampleScene",true,2,""); //Relaoding the same scene works
  156.                         //TNManager.JoinChannel(1, null,true,2,""); //Loading no scene doesn't
  157.                 }
  158.  
  159.         }
  160.  
  161.         public void GetListOfGames () {                        
  162.                 totalServers = TNLobbyClient.knownServers.list.size;
  163.        
  164.                 if (totalServers == 0) {
  165.                         Debug.Log ("No hosted games found");
  166.                         return;
  167.                 }
  168.                 serverListInfo = new ServerList.Entry[totalServers];
  169.                 for (int i = TNLobbyClient.knownServers.list.size-1; i > -1; i--) {
  170.                         Debug.Log ("Server #" + i + " name:" + TNLobbyClient.knownServers.list [i].name+"  player count: "+TNLobbyClient.knownServers.list [i].playerCount);
  171.                         serverListInfo [i] =  TNLobbyClient.knownServers.list [i];
  172.                 }
  173.                 updatingList = false;
  174.         }
  175.  
  176.         public void JoinHostedGame (string hostedGameName) {
  177.                 myServer = null;
  178.                 int serverNumber = -1;
  179.                 for (int i = 0; i < serverListInfo.Length; i++) {
  180.                         if (hostedGameName == serverListInfo [i].name) {
  181.                                 Debug.Log ("Found it! Joining now");
  182.                                 TNManager.Connect(serverListInfo [i].internalAddress, serverListInfo [i].internalAddress);
  183.                                 myServer = serverListInfo [i];
  184.                                 serverNumber = i;
  185.                                 break;
  186.                         }
  187.                 }
  188.                 if (serverNumber == -1) {
  189.                         Debug.Log ("***TELL PLAYER: THAT SERVER IS NO LONGER AVAILABLE");
  190.                 }
  191.         }
  192.  
  193.  
  194.         void OnConnect (bool success, string message)
  195.         {
  196.                 Debug.Log("*** Connected: " + success + " " + message + " (Player ID #" + TNManager.playerID + ")");
  197.  
  198.                 // Make it possible to use UDP using a random port
  199.                 if (success && !TNServerInstance.isLocal) TNManager.StartUDP(Random.Range(10000, 50000));
  200.                 if (hosting) {
  201.                         serverCrerated = true;
  202.                 } else {
  203.                         TNManager.JoinChannel(1, "exampleScene",true,2,""); //Relaoding the same scene works
  204.                         //TNManager.JoinChannel(1, null,true,2,""); //Loading no scene doesn't
  205.                 }
  206.         }
  207.                
  208.         void OnJoinChannel (int channelID, bool success, string msg)
  209.         {
  210.                
  211.                 if (hosting) {
  212.                         Debug.Log ("***JOINED CHANNEL HOSTING!!!");
  213.                         StartCoroutine (WaitForOtherPlayer ());
  214.                 } else {
  215.                         Debug.Log ("***JOINED CHANNEL as guest!!!");
  216.                 }
  217.                 Debug.Log("*** Joined channel #" + channelID + " " + success + " " + msg+"  player count:"+myServer.playerCount);
  218.         }
  219.  
  220.         IEnumerator WaitForOtherPlayer () {
  221.                 Debug.Log ("*** OKAY!!! WAITING FOR SECOND PLAYER!!!");
  222.                 while (myServer.playerCount < 2) {
  223.                         yield return new WaitForSeconds (.5f);
  224.                 }
  225.                 Debug.Log ("*** OKAY!!! SECOND PLAYER IS HERE!!!");
  226.         }
  227.  
  228.         void OnDisconnect ()
  229.         {
  230.                 Debug.Log("*** SOMEONE DISCONNECTED!!!! Are we still connected? "+TNManager.isConnected);
  231.         }
  232.                
  233.         void OnLeaveChannel (int channelID)
  234.         {
  235.                 Debug.Log("*** Left channel #" + channelID);
  236.         }
  237.  
  238.         void onPlayerLeave (int channelID, Player p) {
  239.                 Debug.Log ("*** A PLAYER JUST LEFT!!!");
  240.         }
  241.  
  242.         void OnPlayerJoin (int channelID, Player p) {
  243.                 Debug.Log ("*** OOOP! SOMEONE JUST JOINED!! Our ID:" + TNManager.playerID + " player added:" + p.id);
  244.                 if (TNManager.isHosting) {                     
  245.                         if (myServer.playerCount == 2) Debug.Log ("***TIME TO GET THE PARTY STARTED!!!");
  246.                 }
  247.         }
  248.  
  249.         void OnPlayerLeave (int channelID, Player p) {
  250.                 Debug.Log ("*** OOOP! SOMEONE JUST LEFT!! Our ID:" + TNManager.playerID + " player added:" + p.id);
  251.         }
  252.  
  253.         public void StopServer () {
  254.                 hosting = false;
  255.                 serverCrerated = false;
  256.         Debug.Log ("***SHUTTING DOWN THE SERVER");     
  257.                 TNManager.SetPlayerLimit (0);
  258.        
  259.                 if (TNManager.isInChannel) TNManager.LeaveChannel();   
  260.                 if (TNManager.isConnected) TNManager.Disconnect ();    
  261.                 TNServerInstance.Stop("server.dat");
  262.         }
  263.  
  264. }
  265.  


Example file of RFC calls:
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using TNet;
  5.  
  6. public class tnetBehaviour : TNBehaviour {
  7.         public bool host;
  8.  
  9.         // Use this for initialization
  10.         void Start () {
  11.                 if (host) {
  12.                         StartCoroutine (HostSoundingOff());
  13.                 } else {
  14.                         StartCoroutine (GuestSoundingOff());
  15.                 }
  16.         }
  17.  
  18.         IEnumerator HostSoundingOff () {
  19.                 Debug.Log ("*** STARTING UP HOST SOUNDING OFF");
  20.                 float delay = Time.time + 5;
  21.                 while (gameObject) {
  22.                         if (Time.time > delay) {
  23.                                 delay = Time.time + 5;
  24.                                 Debug.Log ("***we (host) just sounded off. Players in channel: ");
  25.                                 tno.Send ("HostCheckingIn", Target.All);
  26.                                 //                              tno.Send("HostCheckingIn", Target.All, TNManager.playerID);
  27.                         }
  28.                         yield return null;
  29.                 }
  30.         }
  31.         IEnumerator GuestSoundingOff () {
  32.                 Debug.Log ("*** STARTING UP GUEST SOUNDING OFF");
  33.                 float delay = Time.time + 5;
  34.                 while (gameObject) {
  35.                         if (Time.time > delay) {
  36.                                 delay = Time.time + 5;
  37.                                 Debug.Log ("***we (guest) just sounded off");
  38.                                 tno.Send ("GuestCheckingIn", Target.All);
  39.                                 //                              tno.Send("GuestCheckingIn", Target.All, TNManager.playerID);
  40.                         }
  41.                         yield return null;
  42.                 }
  43.         }
  44.  
  45.         [RFC] void HostCheckingIn () {
  46.                 Debug.Log ("Host says hello! ");
  47.         }
  48.  
  49.         [RFC] void GuestCheckingIn () {
  50.                 Debug.Log ("Guest says hello! ");
  51.         }
  52. }
  53.  

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #3 on: July 01, 2017, 10:06:16 PM »
Hey, I went through your code and restructured it a bit. I don't see any reason for RFCs to not work, but maybe this will help. Some problems with your code I'd like to point out:
1. Liberal use of coroutines when unnecessary [TNet provides many properties for you to check state]
2. Relying on the lobby client to determine whether you're hosting a server [TNServerInstance.isActive does the same thing with much less work ;)]
3. Having a coroutine to check for a second player despite subscribing to the OnPlayerJoin event [this event is fired whenever a remote player (not you) joins a channel]
4. Deriving from TNEventReceiver despite setting up separate event listeners anyway [TNEventReceiver handles event subscriptions itself, just override its virtual methods or don't use it at all]
5. Misunderstanding the OnDisconnect event [it's fired when *you* disconnect from the server. OnPlayerLeave is fired when another player disconnects]
And if you'll allow me to nitpick:
6. Typos and inconsistent formatting

tnetMultiplayerExample:
  1. using UnityEngine;
  2. using TNet;
  3.  
  4. [ExecuteInEditMode]
  5. public class tnetMultiplayerExample : MonoBehaviour
  6. {
  7.     public enum IPType
  8.     {
  9.         IP_v_4,
  10.         IP_v_6,
  11.     }
  12.  
  13.     protected static tnetMultiplayerExample _instance;
  14.     public static tnetMultiplayerExample instance { get { return _instance; } }
  15.  
  16.     string serverName;
  17.     public int serverTcpPort = 5127;
  18.     public IPType serverProtocol = IPType.IP_v_4;
  19.  
  20.     void Awake()
  21.     {
  22.         if (Application.isPlaying)
  23.         {
  24.             if (_instance == null)
  25.             {
  26.                 _instance = this;
  27.                 DontDestroyOnLoad(this.gameObject);
  28.             }
  29.             else Destroy(this.gameObject);
  30.             // Choose IPv6 or IPv4
  31.             TcpProtocol.defaultListenerInterface = (serverProtocol == IPType.IP_v_6) ? System.Net.IPAddress.IPv6Any : System.Net.IPAddress.Any;
  32.         }
  33.     }
  34.  
  35.     void OnEnable()
  36.     {
  37.         TNManager.onConnect += OnConnect;
  38.         TNManager.onJoinChannel += OnJoinChannel;
  39.         TNManager.onPlayerJoin += OnPlayerJoin;
  40.         TNManager.onPlayerLeave += OnPlayerLeave;
  41.         TNManager.onDisconnect += OnDisconnect;
  42.         TNManager.onLeaveChannel += OnLeaveChannel;
  43.     }
  44.  
  45.     void OnDisable()
  46.     {
  47.         TNManager.onConnect -= OnConnect;
  48.         TNManager.onJoinChannel -= OnJoinChannel;
  49.         TNManager.onPlayerJoin -= OnPlayerJoin;
  50.         TNManager.onPlayerLeave -= OnPlayerLeave;
  51.         TNManager.onDisconnect -= OnDisconnect;
  52.         TNManager.onLeaveChannel -= OnLeaveChannel;
  53.     }
  54.  
  55.     public void StartServer(string newServerName)
  56.     {
  57.         //check if an old server is still alive and kicking first
  58.         if (TNServerInstance.isActive)
  59.             return;
  60.  
  61.         int udpPort = Random.Range(10000, 40000);
  62.         TNLobbyClient lobby = GetComponent<TNLobbyClient>();
  63.         //add a number to prevent duplicate server names
  64.         serverName = newServerName + "_" + ((uint)(((int)System.DateTime.UtcNow.Ticks) + Random.Range(100000, 900000))).ToString();
  65.         TNServerInstance.serverName = serverName;
  66.         bool success = false;
  67.         if (lobby == null)
  68.         {
  69.             success = TNServerInstance.Start(serverTcpPort, udpPort, "server.dat");
  70.         }
  71.         else
  72.         {
  73.             TNServerInstance.Type type = (lobby is TNUdpLobbyClient) ? TNServerInstance.Type.Udp : TNServerInstance.Type.Tcp;
  74.             success = TNServerInstance.Start(serverTcpPort, udpPort, lobby.remotePort, "server.dat", type);
  75.         }
  76.         if (success)
  77.             TNManager.Connect();
  78.         else
  79.             Debug.Log(name + " [tnetMultiplayerExample] ERROR: Failed to start server");
  80.     }
  81.  
  82.     public void StopServer()
  83.     {
  84.         Debug.Log("***SHUTTING DOWN THE SERVER");
  85.         TNManager.SetPlayerLimit(0);
  86.         if (TNManager.isInChannel) TNManager.LeaveChannel();
  87.         if (TNManager.isConnected) TNManager.Disconnect();
  88.         TNServerInstance.Stop();
  89.     }
  90.  
  91.     void OnConnect(bool success, string message)
  92.     {
  93.         Debug.Log("*** WE Connected: " + success + " " + message + " (Player ID #" + TNManager.playerID + ")");
  94.  
  95.         // Make it possible to use UDP using a random port
  96.         if (success && !TNServerInstance.isLocal) TNManager.StartUDP(Random.Range(10000, 50000));
  97.         //Reloading the same scene works
  98.         TNManager.JoinChannel(1, "exampleScene", true, 2, "");
  99.         //Loading no scene doesn't
  100.         //TNManager.JoinChannel(1, null,true,2,"");
  101.     }
  102.  
  103.     void OnDisconnect()
  104.     {
  105.         Debug.Log("*** WE DISCONNECTED FROM SERVER");
  106.     }
  107.  
  108.     void OnJoinChannel(int channelID, bool success, string msg)
  109.     {
  110.         Debug.Log("*** WE " + (success ? "Successfully joined " : "Failed to join ") + "channel #" + channelID +  " as " + (TNManager.IsHosting(channelID) ? "host" : "guest") + " (" + msg + ")  player count:" + (TNManager.players.Count + 1));
  111.     }
  112.  
  113.     void OnLeaveChannel(int channelID)
  114.     {
  115.         Debug.Log("*** WE Left channel #" + channelID);
  116.     }
  117.  
  118.     void OnPlayerJoin(int channelID, Player p)
  119.     {
  120.         Debug.Log("*** OOOP! SOMEONE JUST JOINED!! Our ID:" + TNManager.playerID + " player added:" + p.name + " (" + p.id + ")");
  121.         if (TNManager.isHosting)
  122.         {
  123.             if (TNManager.players.Count == 1)
  124.             {
  125.                 Debug.Log("***TIME TO GET THE PARTY STARTED!!!");
  126.             }
  127.         }
  128.     }
  129.  
  130.     void OnPlayerLeave(int channelID, Player p)
  131.     {
  132.         Debug.Log("*** PLAYER " + p.name + "(" + p.id + ") JUST LEFT!!!");
  133.     }
  134. }
  135.  
tnetBehaviour:
  1. using System.Collections;
  2. using UnityEngine;
  3. using TNet;
  4.  
  5. public class tnetBehaviour : TNBehaviour
  6. {
  7.     [SerializeField]
  8.     float HeartbeatTickRate = 5f;
  9.  
  10.     void Start()
  11.     {
  12.         StartCoroutine(Heartbeat());
  13.     }
  14.  
  15.     IEnumerator Heartbeat()
  16.     {
  17.         Debug.Log("*** STARTING UP HEARTBEAT");
  18.         while (true)
  19.         {
  20.             if (TNManager.isInChannel)
  21.             {
  22.                 Debug.Log("***we (" + (TNManager.isHosting ? "host" : "guest") + ") just sounded off. Players in channel: ");
  23.                 tno.Send((byte)50, Target.All);
  24.             }
  25.             yield return new WaitForSeconds(HeartbeatTickRate);
  26.         }
  27.     }
  28.  
  29.     [RFC(50)]
  30.     void CheckingIn()
  31.     {
  32.         bool fromHost = TNManager.packetSourceID == TNManager.GetHost(TNManager.lastChannelID).id;
  33.         Debug.Log((fromHost ? "Host " : "Guest ") + "(id: " + TNManager.packetSourceID + ") says hello!");
  34.     }
  35. }
  36.  

I haven't tested it. The code itself is fine, though, so it should work barring any errors in your scene setup / rest of your code.
Note: I used a random RFC ID of 50 for the CheckingIn function. If you already have an RFC using ID 50 then you'll need to change this.

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #4 on: July 02, 2017, 12:41:29 AM »
Thanks for taking the time to reformat/rewrite the code I uploaded. I don't think my code has ever looked more professional, well formatted or typo free.

Unfortunately, it didn't address my problem. Your well crafted code still produces the exact same results as my less than stellar code. Namely, using a loaded scene file for joinChannel allows communication between players. But using a null file still results in non-functioning RFCs.

In this image, on the left, I used your code with a loaded scene file for the joinChannel. You can see the output below it. On the right, I did the joinChannel call with a null and you can see that the "shout outs" don't reach the other player.


cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #5 on: July 02, 2017, 05:18:00 AM »
I just made a little test application and confirmed that it works as expected. So it has to be something in your setup that's causing the problem.
Some things to double-check:
1. Is "Run In Background" enabled under Player settings?
2. Are you using TNManager.Instantiate(...) correctly?
3. Are you checking tno.isMine when necessary?

I just re-read your posts and realized you never instantiate an object on join. Are you trying to work with static objects? This changes things a bit. For player objects (and most everything, really) you should use TNManager.Instantiate(...). Make sure your TNObject has an ID of 0 on your prefab.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #6 on: July 02, 2017, 06:05:46 AM »
Just tested with static objects too:
Static TNObject's channelID is set in its Awake function to whatever TNManager.lastChannelID is at that moment. At startup, this is 0.

So the fix in your case is to change your TNManager.JoinChannel(1, ...) call to TNManager.JoinChannel(0, ...) assuming the static TNObject is present in your initial scene.
The more flexible way of handling this is to keep track of all your static TNObject's and in the OnJoinChannel handler you can use TNObject.TransferToChannel(newChannelID) for those that you want to stick around. Note that transferring the TNObject to a new channel does not transfer the whole object hierarchy, you will have to manage that yourself (as the function summary says).
Alternatively, you can make sure that whatever channel the static TNObject is in is never left. Always remain in that channel, even if you join a new channel.

Note to ArenMook: is this intended? Wouldn't it make more sense for static TNObject's to get the channelID from the first joined channel *if the player is not in a channel* when its Awake is called? I think you can yield in Awake and Start. Thinking more about it, this is probably a super rare special case and not worth the cycles. Better to encourage people to join channels sequentially, starting at 0.

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #7 on: July 02, 2017, 12:46:21 PM »
Thanks again for the help! I didn't have "run in Background" turned on but even with that enabled a null scene request still didn't work for me.

BTW, I'm using 5.5.3f1. I don't know if that's a factor but I'm not sure what else would be different. Instantiating objects is the same issue as the RFCs for me. If I load a scene, it all works fine. If I keep the joinChannel null then they fail to share.

Not a deal breaker. Right now I'm just reloading the same scene and having no problem with RCCs or RFCs so I guess I'll just keep going with that work around.

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #8 on: July 02, 2017, 06:00:40 PM »
Nope, I crashed and burned using 5.6 as well. Here's a very simple way to replicate my issue:

Load up the tNet example scene (scene name: "0. Menu"). In the inspector window for the Example Menu, change the Examples to 7 and make Element 6 = "0. Menu".

Create a game object and attach your tnetBehaviour script from above and then add a TN Object script to it. (Of course, select the "Assign Unique ID" button").

Compile & run 2 iterations of this with one as host and one as guest. Have both of them select the "0. Menu" scene. And it'll work perfectly with the "... says hello" message popping up like it should.  (Just like the left side of the screengrab I posted before).  Use whatever method you want to display the Debug.Log messages (run one in editor, for example).

Now go into the ExampleMenu script and change "TNManager.JoinChannel(i + 1, sceneName, true, 255, null);" to "TNManager.JoinChannel(i + 1, null, true, 255, null);"

Compile and run 2 iterations again and repeat the host/guest selection along with the "0. Menu" selection. Now the "... says hello" messages won't make it across. (Just like the right side of the screengrab I posted before).

If you DO have success running them with the "null" setting then I'm at a total loss since I've now tried running it on the current and previous versions of Unity.

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #9 on: July 02, 2017, 07:09:44 PM »
Ah, that helps a lot. So it is like I thought in my previous post: the TNObject is in channel 0 and when you click the "0. Menu" (which is actually i=6 with your modifications) you join channel 6. When your tnetBehaviour script calls tno.Send(...), it first checks if the player is in the TNObject's channel - resolves to TNManager.IsInChannel(0) - which comes back as false because you're only in channel 6.

Try the solutions I suggested in my previous post and you should be golden (always remaining in the same channel as the TNObject OR transferring the TNObject to your channel).

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #10 on: July 02, 2017, 07:45:22 PM »
Bingo!!!

Okay, dropping it to 0 in my project allowed me to successfully join the channel with NULL and still have the RFCs and RCCs work perfectly. I'm all set now.

So, if I'm following correctly, even if you're reloading the same scene it iterates the channel number up one spot necessitating the +1?

Thanks again for resolving this for me!


cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #11 on: July 02, 2017, 07:50:11 PM »
Nope - it's just that TNObject's are assigned to the last channel you joined upon their instantiation. If you aren't in a channel when the TNObject is instantiated then it's set to 0.

dustin1138

  • Newbie
  • *
  • Thank You
  • -Given: 1
  • -Receive: 0
  • Posts: 15
    • View Profile
Re: RFC & RCC don't work when using null for joinChannel scene?
« Reply #12 on: July 02, 2017, 07:56:37 PM »
Ah, got it. Thanks for clarifying.