- Home /
HLAPI RPC synchronization - how to wait for a RPC
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");
}
Answer by hawken · Sep 30, 2017 at 06:58 AM
Hi @MiniForge
use ondestroy only, think of it as a fast Rpc ;)
void OnDestroy()
{
Debug.Log("Hullo");
}
Answer by gon777 · Feb 14, 2018 at 02:54 PM
I'm having the same issue, right now I have to delay networkserver.destroy() a bit. even though I believe it's not the best way.
Your answer
Follow this Question
Related Questions
Animation over network using rpcs 0 Answers
Unity networking tutorial? 6 Answers
can't switching between weapons in multiplayer game? 0 Answers