Hello,
I've noticed when running a local server that my Network.Destroy will execute before the RPC call finishes on clients, which results in an RPC error being thrown. If I invoke the Destroy with a 0.01 second delay the RPC will not throw the error.
What is the proper way to wait for a RPC to complete since clients can have varying ping? I would prefer not to have to write another command method to keep track of the state of each client's code completion.
https://docs.unity3d.com/Manual/UNetActions.html
Error: Could not find target object with netId:10 for RPC call ClientRpc:InvokeRpcRpcTest
UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()
// This function is a CMD but called from elsewhere
void CollapseTree(){
if(!isServer){
return;
}
// Debug.Log("Tree is collapsing");
// Play a collapse sound
// Instantiate trees
for (int i = 0; i < 4; i++){
Vector3 pos = transform.position;
GameObject go = Instantiate(logPrefab, new Vector3(pos.x, pos.y + (i * 2), pos.z), Random.rotation);
NetworkServer.Spawn(go);
}
RpcTest();
// Tree will be removed from both server and client now
NetworkServer.Destroy(this.gameObject);
}
void OnDestroy(){
// PLAY THE CLIENT SOUND HERE!
}
[ClientRpc]
void RpcTest(){
Debug.Log("Hullo");
}
↧