I’m trying to send an RPC to all clients when a single client disconnects (willingly, timed out, etc). The NetworkManager on the server should be able to track that but I can’t seem to figure out how to call for that trigger.
I understand that (now) the server stuff is completely independent from the client stuff… which is, fine, I’ll call an RPC if I need the clients to register it but none of the things I’ve tried work. Can someone type what they’ve used (that works), please?
Thanks.
P.S. - Having documentation on both legacy and UNET is not helping… even stuff that aren’t labelled as “(legacy)” don’t seem to work. I haven’t found a single bit of info in the manual on how to deal with disconnects.
public virtual void OnServerDisconnect(NetworkConnectionconn)
{
Debug.Log (“Something happened”);
}
It doesn’t work; neither clients nor server sends “Something happened” on the console. I just want clients to call a function when another disconnects.
Actually, this is the only thing that doesn’t seem to work now. The server calls the Rpc function but the remaining clients don’t receive it for some reason.
public override void OnServerDisconnect(NetworkConnectionconn)
{
base.OnServerDisconnect(conn);
Debug.Log (“Something happened”);
Rpc_Step1();
}
[ClientRpc]
public void Rpc_Step1()
{
Debug.Log (“Step1”);
Step2 ();
}
public void Step2()
{
Debug.Log (“Step2”);
}
You can only send Rpc’s to objects with NetworkBehaviour. This means that you can’t Rpc in the NetworkManager. You need a seperate object with the NetworkBehaviour where you can then call the Rpc function. Remember to also add a NetworkIdentity to that object.
The object also needs to be spawned by the server. So you should make it a prefab, and use the Spawn function when you create the server. It will automatically be spawned on the clients too then.