I think so? Any objects in the scene you load via JoinChannel will be networked. Objects from previous scenes (like your startup scene) won't automatically become networked.
You shouldn't have any objects in your startup scene that require RFCs because you aren't connected to a channel at startup. How could they be aware of something that didn't exist at their birth?
Well, the same way we do, I guess, by being told about them:
public class GameManager : TNBehaviour
{
void OnEnable()
{
TNManager.onJoinChannel += OnJoinChannel;
}
void OnDisable()
{
TNManager.onJoinChannel -= OnJoinChannel;
}
private void OnJoinChannel(int channelID, bool success, string message)
{
if (!success)
{
Debug.LogError(name + " Saw failed JoinChannel (" + message + ")");
return;
}
tno.Initialize();
tno.Send(45, Target.All, TNManager.isHosting ? "HOST initialized" : "CLIENT initialized");
}
[RFC(45)]
void TestRFC(string msg)
{
Debug.Log("Message from: " + msg);
}
}
Add the following to TNObject.cs:public bool IsInitialized = false;
public void Initialize()
{
if (IsInitialized) return;
Unregister();
channelID = TNManager.lastChannelID;
Register();
if (mCallDataChanged && onDataChanged != null)
{
mCallDataChanged = false;
onDataChanged(mData);
}
rebuildMethodList = true;
IsInitialized = true;
}
It's super sloppy but I tested it and it works. You could probably hook TNObject itself up to the OnJoinChannel event but that'd require modifying some of its existing code. So for the sake of posting this I went with an approach that only adds new code.
Oh, I also just realized that maybe you don't need *RFCs* but don't know about the glory of custom packets... I probably should've told you about those in like the first post. My bad.
You can use custom packets by calling TNManager.BeginSend and TNManager.EndSend directly. Set the packet handler with TNManager.SetPacketHandler. You only get one packet handler per packetID which is perfectly fine for a singleton manager.
And to sort of explain why getting RFCs working on an un-networked object is such a hassle:
RFCs belong to objects which belong to channels. The benefits of an RFC are: ease of use (one line!), instanced, and the ability to save the call on the channel so it's automatically sent to new players.
So if your object doesn't belong to a channel then RFCs can't work. The code snippet above forcefully registers your object with the channel to get its RFCs working.
Maybe it'd help to think of RFC (Remote Function Call) as RCC (Remote *Channel* Call). But TNet uses RCC for something else (Remote Creation Call), so yeah