16
TNet 3 Support / 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?
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?
- // My tno script
- IEnumerator Start()
- {
- while (TNManager.isJoiningChannel) yield return null;
- TNManager.onPlayerJoin += OnPlayerJoin;
- if (TNManager.isHosting)
- CachedCrashCamera.SetupCamera();
- }
- private void OnPlayerJoin(int channelID, TNet.Player p)
- {
- // Send an RFC with the latest Camera settings to the newly joined player
- if (TNManager.isHosting)
- {
- tno.Send(1, p, transform.position, CachedCrashCamera.IsScrolling, CachedCrashCamera.ScrollIndex, (int)CachedCrashCamera.ScrollDir);
- }
- }
- [RFC(1)]
- public void RecieveCameraPositionAndState(Vector3 pos, bool isScrolling, int nodeIndex, int scrollDir)
- {
- Debug.Log("SHOULD GET CAMERA DETAILS, BUT FAILING!");
- // Do important things here
- }