Author Topic: OnPlayerJoin with static tno RFC error  (Read 2749 times)

rxmarcus

  • Jr. Member
  • **
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 62
    • View Profile
OnPlayerJoin with static tno RFC error
« on: July 27, 2017, 05:22:00 PM »
I'm trying to simplify some of my netcode. Previously for certain static (already in the scene) tno's I would have a newly joined player send an RFC to the Host to request the most up to date relevant details.

Instead, I thought it'd be much cleaner and simpler, to instead subscribe to the OnPlayerJoin event inside my tno script that would send an RFC to the newly joined player. The issue I'm having though is that I get "[TNet] Trying to execute RFC #1 on TNObject #20 before it has been created." warning when the player joins and he obviously doesn't receive the RFC.

Here is my code, is there something simple that I am doing wrong here? Or are there issues with using the OnPlayerJoin subscription inside a static tno object?

  1. // My tno script
  2.     IEnumerator Start()
  3.     {
  4.  
  5.         while (TNManager.isJoiningChannel) yield return null;
  6.  
  7.         TNManager.onPlayerJoin += OnPlayerJoin;
  8.  
  9.         if (TNManager.isHosting)
  10.             CachedCrashCamera.SetupCamera();
  11.     }
  12.  
  13.     private void OnPlayerJoin(int channelID, TNet.Player p)
  14.     {
  15.         // Send an RFC with the latest Camera settings to the newly joined player
  16.         if (TNManager.isHosting)
  17.         {
  18.             tno.Send(1, p, transform.position, CachedCrashCamera.IsScrolling, CachedCrashCamera.ScrollIndex, (int)CachedCrashCamera.ScrollDir);
  19.         }
  20.     }
  21.  
  22.     [RFC(1)]
  23.     public void RecieveCameraPositionAndState(Vector3 pos, bool isScrolling, int nodeIndex, int scrollDir)
  24.     {
  25.         Debug.Log("SHOULD GET CAMERA DETAILS, BUT FAILING!");
  26.        
  27.         // Do important things here
  28.     }
  29.  

cmifwdll

  • Global Moderator
  • Sr. Member
  • *****
  • Thank You
  • -Given: 0
  • -Receive: 149
  • Posts: 285
  • TNet Alchemist
    • View Profile
Re: OnPlayerJoin with static tno RFC error
« Reply #1 on: July 27, 2017, 07:21:31 PM »
Working flawlessly for me. Using your exact code (including your version of TNet from the dropbox link). I placed a TNObject on a scene object and assigned its non-zero ID.
Are you using an existing TNObject like that or is it dynamically instantiated? I'll go try with an instantiated TNObject.

edit: tried with an instantiated TNObject and still not experiencing your error. Client 1 joins, instantiates the object using TNManager.Instantiate. Client 2 joins. Client 2 automatically creates the object that Client 1 instantiated. Client 1 sends the RFC from OnPlayerJoin. Client 2 receives the RFC. So it must be something else in your setup. I'd check that you are instantiating the object via TNManager.Instantiate or that the object exists on each client with the same TNObject ID if you're instantiating it some other way.
« Last Edit: July 27, 2017, 07:37:08 PM by cmifwdll »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: OnPlayerJoin with static tno RFC error
« Reply #2 on: August 03, 2017, 04:20:58 AM »
Unrelated: so your Start function waits for TNManager to finish joining the channel, then adds a Player Join notification listener just to send a message inside? Why not just have that message be sent when it actually changes by using a saved RFC call? All saved RFCs get called while the join is in progress, before the join operation finishes. All you're doing is introducing a delay where there shouldn't be any.

tno.Send("RfcFunctionName", Target.OthersSaved, ...);