Tasharen Entertainment Forum

Support => TNet 3 Support => Topic started by: Eyeshock on July 10, 2013, 07:21:25 AM

Title: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: Eyeshock on July 10, 2013, 07:21:25 AM
Hi there. I'm trying to integrate TNET into my already existing networked game. In the past, I've simply handled everything up until the gameplay via the main menu scene (setup lobby, players lobby, then run game based on map/difficulty choices, etc.)

I'm having no luck making this work with TNET and I'm guessing this join channel thing is to blame. So I can't execute any RFC before joining channel between players and the only way to join channel is to load a new scene? (this may be blatantly simple, but to be fair: 3 pages of documentation...)

AND...if that's the case, and I have a Multiplayer Manager script keeping track of my players saved data (preserved profile data, similar to games like League of Legends, Starcraft 2), can I preserve that gameobject with a TNObject script from hosting/connection scene to lobby scene (the 'joined' channel)?

And finally, can I preserve a manager object (with TNObject) between levels using TNManager.Loadlevel once I'm in the channel lobby?

So to summarize: is it absolutely necessary to load a new scene after connecting?

To be perfectly honest, I'm starting to doubt my decision to pick up this asset. It's great for folks looking for a fast track to sync, especially for standalone servers, but I'm yet to find any advantage to the swap (not to discredit your development packages; I am very fond of NGUI). Maybe when I actually get to the game-play, my luck will change. Thanks in advance for your support.

Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: ArenMook on July 10, 2013, 12:35:57 PM
You can pass 'null' for the scene name for JoinChannel.

You can have TNObjects travel from one scene to another (DontDestroyOnLoad their game objects).
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: Eyeshock on July 11, 2013, 02:15:13 AM
That seems to work just fine, and fixed the mass of issues I was encountering.

The big problem I'm having now is I can't execute any [RFC] calls.
  1.        
  2.  
  3. void OnNetworkJoinChannel(bool success, string message)
  4.         {
  5.                 Debug.Log("Joining Network Channel: Success? " + success + " Message:" + message);
  6.                
  7.                 // Let All Users Know I'm Here
  8.                 Debug.Log ("Calling Notify Network...");
  9.                 tno.Send("NotifyNetwork", Target.All);
  10.         }
  11.        
  12.         void OnNetworkPlayerJoin(Player newPlayer)
  13.         {
  14.                 Debug.Log("ID "+ newPlayer.id + ", " + newPlayer.name + " Joined Network.");
  15.         }
  16.        
  17.        
  18.         void AddPlayerToClientList(string newPlayerName, int playerID)
  19.         {
  20.                 MPPlayer tempPlayer = new MPPlayer();
  21.                 tempPlayer.playerName = newPlayerName;
  22. //              tempPlayer.playerNetwork = view ;
  23.                 playerList.Add(tempPlayer);
  24.         }
  25.        
  26.        
  27.         [RFC] void NotifyNetwork()
  28.         {
  29.                 Debug.Log ("Calling Notify Network!");
  30.         }
  31.        

I keep getting the error: "Unable to execute function 'NotifyNetwork'. Did you forget an [RFC] prefix, perhaps?"
I'm currently inheriting from TNBehavior.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: ArenMook on July 11, 2013, 06:53:05 PM
Where is this script attached? Is it on some instantiated prefab?

Also -- not quite sure why you are sending NotifyNetwork when you already get the OnNetworkPlayerJoined notification?
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: Eyeshock on July 11, 2013, 07:05:48 PM
Where is this script attached? Is it on some instantiated prefab?

Also -- not quite sure why you are sending NotifyNetwork when you already get the OnNetworkPlayerJoined notification?

(http://www.eyeshock.com/_tempdocs/multiplayerManagerRFC.png)

Script is attached to existing gameobject at game start. I'm calling NotifyNetwork simply for learning/testing purposes, to make sure RFC is working. I would normally be calling an updated version of AddPlayerToClientList (old ver is based on RPC/Unity.Network), however I haven't started updating all my RPCs yet because...well...I can't get NotifyNetwork() to execute.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: ArenMook on July 11, 2013, 07:46:27 PM
Try simply doing that tno.Send inside Update() function when you press a specific key:
  1. void Update()
  2. {
  3.     if (Input.GetKeyDown(KeyCode.S)) tno.Send("NotifyNetwork", Target.All);
  4. }
Does that work?
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: Eyeshock on July 11, 2013, 07:52:52 PM
(http://www.eyeshock.com/_tempdocs/multiplayerManagerRFC2.png)

Same error. It's not like RFC is broken either; I'm using the chat gameobject from your example scene in the same scene as multiplayerManager and it's working fine.

If I absolutely have to, I'll prolly try seperating my Mplayer class (player data) from MultiplayerManager (connection functions), and detaching them both from the TNManager to see if that changes anything; maybe even try instantiating what I can after connection. But obviously, I'd really rather not do that - nor does it explain why the error reported suggests the [RFC] prefix is being ignored.

BLAAHBLAHBLAHAAALL!H!H!H  :P
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: Eyeshock on July 12, 2013, 05:33:59 AM
SO WEIRD; I'm having no problems with the quick swapping out RPC for RFC on other instantiated prefabs, but this object continues to error out on RFC calls. Does it have anything to do with it being on the same object as TNManager?

I tried instantiated it as a prefab in an empty scene; same problem, so the issue is either in the script or something to do with the gameobject; I have included the entire script, though the mass of it is outdated RPC calls (comment shows the division).

Please lemme know if you see the problem. I've got TNET to function pretty well with my combat/collision stuff, so I'm convinced it's a good system; I bet I can find a work around for this issue (separating RFCs from the Abstract class), but obviously I'd rather now. Thanks again.

  1.  
  2. using UnityEngine;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using TNet;
  6.  
  7. public class MultiplayerManager : TNBehaviour {
  8.        
  9.         public enum GameState
  10.         {
  11.                 Setup,
  12.                 GameLobby,
  13.                 CharacterSelect,
  14.                 Loading,
  15.                 Playing,
  16.                 BetweenLevels,
  17.                 EndGame
  18.         }
  19.        
  20.         public GameState matchState = GameState.Setup;
  21.         public bool playerReady = false;
  22.        
  23.         private string _matchName = "" ;
  24. //      private string _matchPassword = "" ;
  25.         private int _matchMaxUsers = 3 ;
  26.        
  27.         public static MultiplayerManager instance ;
  28.        
  29.        
  30.        
  31.         public System.Collections.Generic.List<MPPlayer> playerList = new System.Collections.Generic.List<MPPlayer>();
  32.         public System.Collections.Generic.List<GameObject> NetworkedPlayerPrefabs;
  33.         public System.Collections.Generic.List<SceneSettings> sceneList = new System.Collections.Generic.List<SceneSettings>();
  34.        
  35.         public GameObject playerCharacterPrefab;
  36.        
  37.        
  38.         public SceneSettings currentScene;
  39.         public int oldPrefix ;
  40.         public bool isMatchStarted = false;
  41.        
  42.        
  43.         // public TNObject tno;
  44.        
  45.         public int NumberOfConnectedPlayers;
  46.        
  47.        
  48.         void Start()
  49.         {
  50.                
  51.                 TNObject tno = gameObject.GetComponent<TNObject>();
  52.                
  53.                 GameReference.multiplayerManagerScript = this;
  54.                 DontDestroyOnLoad(gameObject);
  55.                 instance = this;
  56.                 // playerName = PlayerPrefs.GetString("PlayerName");
  57.                 currentScene = sceneList[0];
  58.         }
  59.        
  60.         void Update()
  61.         {
  62.                 NumberOfConnectedPlayers = TNManager.players.size;
  63.                
  64.                
  65.                  if (Input.GetKeyDown(KeyCode.S)) tno.Send("NotifyNetwork", Target.All);
  66.         }
  67.        
  68.         void FixedUpdate()
  69.         {
  70.                 instance = this;
  71.                
  72.         }
  73.        
  74.         // Starts local server using TNet Networking
  75.         public void StartServer(string serverName, string serverPassword, int maxUsers)
  76.         {
  77.                 _matchName = serverName ;
  78.                 _matchMaxUsers = maxUsers ;
  79.                
  80.                 TNServerInstance.Start(5127, 5128);
  81.                 TNManager.playerName = GameReference.gameSettingsScript.characterName;
  82.                 //AddPlayerToClientList(TNManager.playerName, TNManager.playerID);
  83.                 ConnectToServer("127.0.0.1");
  84.                
  85.         }
  86.        
  87.         // TNET Networking Setup; connects to server using provided IP
  88.         public void ConnectToServer(string IP2Connect)
  89.         {
  90.                 Debug.Log ("Attempting to Connect to Server at -" + IP2Connect + "-.");
  91.                 TNManager.Connect(IP2Connect);
  92.         }
  93.        
  94.         void OnNetworkError(string error)
  95.         {
  96.                 Debug.LogError("Network Error: " +  error);
  97.         }
  98.        
  99.         void OnNetworkConnect (bool success, string message)
  100.         {
  101.                 Debug.Log("Joining Network: Success? " + success + " Message:" + message);
  102.                
  103.                
  104.                 // Join Channel
  105.                 TNManager.JoinChannel(123, null);
  106.                
  107.                 // Add Player to List of Clients
  108.                 //TNManager.playerName = GameReference.gameSettingsScript.characterName;
  109.                 //AddPlayerToClientList(TNManager.playerName, TNManager.playerID);
  110.         }
  111.        
  112.        
  113.         void OnNetworkJoinChannel(bool success, string message)
  114.         {
  115.                 Debug.Log("Joining Network Channel: Success? " + success + " Message:" + message);
  116.                
  117.                 // Let All Users Know I'm Here
  118.                 Debug.Log ("Calling Notify Network...");
  119.                 tno.Send("NotifyNetwork", TNet.Target.All);
  120.         }
  121.        
  122.         void OnNetworkPlayerJoin(Player newPlayer)
  123.         {
  124.                 Debug.Log("ID "+ newPlayer.id + ", " + newPlayer.name + " Joined Network.");
  125.         }
  126.        
  127.        
  128.         void AddPlayerToClientList(string newPlayerName, int playerID)
  129.         {
  130.                 MPPlayer tempPlayer = new MPPlayer();
  131.                 tempPlayer.playerName = newPlayerName;
  132. //              tempPlayer.playerNetwork = view ;
  133.                 playerList.Add(tempPlayer);
  134.         }
  135.        
  136.         [RFC]
  137.         void NotifyNetwork()
  138.         {
  139.                 Debug.Log ("Calling Notify Network!");
  140.         }
  141.        
  142.        
  143.         // OLD NETWORKING FUNCTIONS BELOW
  144.        
  145.        
  146.         /*
  147.         void OnServerInitialized()
  148.         {
  149.                 Server_PlayerJoinRequest(GameReference.gameSettingsScript.characterName, Network.player);
  150.         }
  151.         */
  152.         void OnConnectedToServer()
  153.         {
  154.                 //networkView.RPC("Server_PlayerJoinRequest", RPCMode.Server, playerName, Network.player);
  155.                        
  156.         }
  157.        
  158.         void OnPlayerDisconnected(NetworkPlayer networkPlayerID)
  159.         {
  160.                 networkView.RPC("Client_RemovePlayer", RPCMode.All, networkPlayerID);
  161.         }
  162.        
  163.         void OnDisconnectedFromServer()
  164.         {
  165.                 playerList.Clear();
  166.         }
  167.        
  168.  
  169.        
  170.         void OnPlayerConnected(NetworkPlayer networkPlayerID)
  171.         {
  172.                 foreach(MPPlayer pl in playerList)
  173.                 {
  174. //                      networkView.RPC("Client_AddPlayerToList", networkPlayerID, pl.playerName, pl.playerNetwork);
  175.                 }
  176.                
  177.                 networkView.RPC("Client_GetMultiplayerMatchSettings", networkPlayerID, currentScene.sceneName, "", "");
  178.         }
  179.        
  180.        
  181.        
  182.  
  183.         void Client_RemovePlayer(NetworkPlayer view)
  184.         {
  185.                 MPPlayer temppl = null;
  186.                 foreach(MPPlayer pl in playerList)
  187.                 {
  188. //                      if(pl.playerNetwork == view)
  189. //                      {
  190. //                              temppl = pl;
  191. //                      }
  192.                 }
  193.                 if(temppl != null)
  194.                 {
  195.                         playerList.Remove(temppl);
  196.                 }
  197.         }
  198.        
  199.  
  200.         void Client_GetMultiplayerMatchSettings(string scene, string mode, string others)
  201.         {
  202.                 currentScene = GetScene(scene);
  203.         }
  204.        
  205.  
  206.         void Client_LoadMultiplayerScene(string scene, int prefix)
  207.         {
  208.                
  209.                 // Spawn Player
  210.                 // Client_SpawnPlayer();
  211.                
  212.                
  213.                 // So we only recieve messages for new prefix
  214.                 Network.SetLevelPrefix(prefix);
  215.                
  216.                
  217.                 Application.LoadLevel(scene);
  218.                
  219.         }
  220.        
  221.         public void Client_SpawnPlayer(Vector3 spawnPoint)
  222.         {
  223.                 Debug.Log ("Spawning Local Player");
  224.                
  225.                 // Create Player Prefab
  226.                 // GameReference.localPlayerObject = Network.Instantiate(playerCharacterPrefab, Vector3.zero, Quaternion.identity, 0) as GameObject;
  227.                 TNManager.Create(playerCharacterPrefab, spawnPoint, Quaternion.identity);
  228.                
  229.                 // GameReference.localPlayerObject.name = GameReference.playerCharacterScript.Name;
  230.                
  231.                 //GameReference.localPlayerObject.transform.localScale = new Vector3(1,1,1);
  232.         }
  233.        
  234.         public SceneSettings GetScene(string name)
  235.         {
  236.                 SceneSettings get = null;
  237.                
  238.                 foreach(SceneSettings st in sceneList)
  239.                 {
  240.                         if(st.sceneName == name)
  241.                         {
  242.                                 get = st;
  243.                                 break;
  244.                         }
  245.                 }
  246.                
  247.                 return get;
  248.         }
  249.        
  250.        
  251.        
  252.        
  253.        
  254. }
  255.  
  256.  [System.Serializable]
  257. public class MPPlayer
  258. {
  259.         public int playerID ;
  260.         public string playerName = "";
  261.        
  262. }
  263.  [System.Serializable]
  264. public class SceneSettings
  265. {
  266.         public string sceneName;
  267.         public string sceneLoadName;
  268.         public Texture sceneLoadTexture;
  269. }
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: ArenMook on July 12, 2013, 01:09:21 PM
Interesting. In Starlink I have a TNObject on another game object that travels from scene to scene (not on the TNManager), but its ID is below 255 -- 10. Which game object it's on shouldn't matter though. Is it possible that you have more than one TNObject with the same ID? When instantiating new game objects it's important to make sure that they have unique IDs. Prefabs should have TNObject IDs set to 0.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: Eyeshock on July 12, 2013, 02:24:33 PM
Yeah; it's got a unique ID both at run-time and instantiation. I tried changing the ID in different ways with no change.

Also in the case of prefabs, setting them to 0 has caused me issues already. I instantiate a number of monsters of the same prefab, and one of them always came out 0, so I've been setting prefabs at intervals of 1000.

I'm going to try making another script and attaching it to the object with a garbage RPC, then try it on a prefab that works with RFC and see if it's specifically something in MultiplayerManager.cs or the gameobject itself.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: ArenMook on July 12, 2013, 02:37:03 PM
How do you instantiate them? You need to use TNManager.Create to do that. If you don't, TNObject IDs won't be set correctly.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: Eyeshock on July 22, 2013, 08:04:09 PM
Yes, I am using TNManager.Create to create prefabs, and they are present in the objects list. I am having no problems with prefabs in the gameplay scene.

I've conducted a lot of trial and error, and even tried some workarounds:

I tried to separate the RFCs from the MultiplayerManager script and call them remotely. It turns out the RFCs aren't even being attempted; if the object in question doesn't exist or does exist, it doesn't matter: same error about 'missing RFC prefix'.

I tried joining a new scene via the JoinChannel and running the RFCs there, and that was a no-go as well.

I tried calling the RFCs in the gameplay scene where I have a lot of networking already; same error.

I tried calling the working RFCs from gameplay on the MultiplayerManager script; same error.

However, if I call RFCs on any other objects or script, it works fine.

Simply stated: It doesn't seem like TNObject will even attempt the call on a script attached to TNManager's gameobject. This does not seem to be the case in the example scenes? In any case, I've sorta hit a wall on this one; I'm not entirely sure what else I can try.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: ArenMook on July 23, 2013, 04:28:43 AM
If you can clean up your project to the bare minimum and send me the example of it not working correctly, I can look into what's wrong.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: Jeremy Alessi on July 25, 2013, 11:32:21 AM
I had the issue of [RFC] tags not working. The solution appears to have been to not use a prefabbed GameObject (I was modifying a previously existing script). I built the same GameObject from scratch (still using the same script) and all of a sudden my [RFC]'s began working. It's possible that it was something else but if so I cannot identify any other changes that made a difference.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: pyscho2day on August 01, 2013, 01:46:00 PM
Would having a TNObject ID of 1001 cause the problem Aren?  I remember reading that there is a limit to 255.  @Eyeshock change the ID from 1001 to 0 and see if that helps any.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: ArenMook on August 01, 2013, 02:47:30 PM
RFC ID limit is 255. Static TNObject IDs have a soft limit of 32767.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: pyscho2day on August 03, 2013, 07:02:17 PM
I have had the same issue now as well.  I did as Jeremy mentioned and just recreated the GameObject and now it works.  I wonder if something got stuck when upgrading.

Just to note, it was a static Empty GameObject with 1 script and the TNObject Script.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: aikshutan on August 17, 2013, 05:34:40 AM
Hi,

I encounter the same problem as well. My scene is pretty simple. A sphere with tnObject ID 10. Apparently the tno ID is not capture or response the way it should be.
I tried RFC(ID) too, but it don work too.

The project contain 2 scene, first is login.scene (when detected LAN server/ host, it will connect and join the channel, and launch my second scene "TestRFC.scene", that is where the sphere gameobject store in.)
I could see the sphere(this mean editor had connected to tnet lan server), upon clicking on sphere, "Unable to execute function xxxx. Did you forget an [RFC] prefix, perhaps?"

these are the codes attach to sphere gameObject
        void OnPress(bool Status)
   {
      if (!Status) return;
      tno.Send(1,Target.All, 12);
      
   }
   
[RFC(1)] void ReceivePressOnTime (int Timing)
   {
      MyCount+=1;
      print("MyCount: " + MyCount);
      print ("ReceivePressOnTime :   " +Timing);
   }

It work when i delete the (original scene asset) sphere gameObject, and recreate a new one, and reattach TNObject component, set the id to 10, and my class which react to OnPress. Then it suddenly work. I don have chance to try restart Unity Application to test whether or not the problem will solve by restarting the unity or window.

Somehow i manage to find the steps to recreate the problem.
I going to repeat the step for creating second scene : TestRFC.scene
New Scene
Attach TouchHandler.cs to Camera gameObject
Create a sphere gameObject
Attach TNObject (don set any id, left the id to default 0)
Save scene
Open Login scene. (any TNManager component which can connect to Standalone server, make sure loadlevel "TestRFC" when joining channel)
Run LoginScene (when TestRFC scene was loaded, try click on the sphere. By right, nothing should be flag out in message, as i guess 0 is not meant for communicating..)
Stop the game, launch TestRFC.scene
Change the TNObject id to 1, then save, and run Login.scene
Upon clicking on the sphere, the alert "Unable to execute function with ID of '1'. Make sure there is a script that can receive this call."
After this point, no matter what number u change in tno.id, the same error will occur.
If you delete the sphere gameObject, and recreate it, reattach all require components, but do remember to fill in tno.id to not 0, then save and test run. Then it work.

Basically, my cause for this is, i forgot to set TNObject ID when i attached it in first place. Hope this help you to recreate the problem. Sorry for my english.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: pyscho2day on August 17, 2013, 04:14:49 PM
I was able to duplicate the error with and object by just changing the object ID in the TNObject script.  Instead of recreating the entire object i just removed the TNObject script, saved the scene, and added it back and set to the new ID and it is now working.

Any thoughts on this Aren?

Actually i just saw that there is an update.  I will see if i can still reproduce after updating.
Guess i will have to try later, its not on the asset store yet. 

/twiddles thumbs while waiting for it to get approved
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: aikshutan on August 17, 2013, 09:48:24 PM
You are right, by removing tnobject, and reassign it back and set the id, the problem will solve.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: ArenMook on August 18, 2013, 06:32:00 AM
I just followed your steps to the letter, and everything worked as expected -- no issues.

One odd thing I did notice though, I ran the scene with the TNObject ID of (0), clicked on it 3 times -- nothing, as expected. I then stopped the game, went into the scene directly, and saw the click result (Debug.Logs in my case) -- so the functions were executed in edit mode as soon as I went back to the scene.

But aside from that, everything worked correctly.

Unity 4.2 / TNet 1.8.0.
Title: Re: Required to Join Channel/Load New Scene to use RFC/See Other Players?
Post by: aikshutan on August 19, 2013, 12:40:57 AM
After solving the router port forwarding issue, i can never recreate the same problem address in this post again. Kind of weird, bt i don think that is the reason that causing it. (Btw, i did run Normalize IDs yesterday, nt sure is that make the different. I shall stop guessing ard. It all work all fine for me now)
Thanks!

Unity 3.5.7 / TNet 1.7.3