- Home /
Force local client RPC to fire immediately?
It seems that making an RPC call will not execute that call immediately on the local client... it has the possibility of happening on the next frame. This really should happen right away (as if you made a direct function call) on the host, to allow for deliberate timing of events on the host - especially since it's authoritative and should be in charge of the correct game state. In order to support a local AND online multiplayer game, the local multiplayer version goes through the same networking code paths, and having local RPCs not fire immediately can cause all sorts of timing problems.
Is this a legitimate bug, or is it by design? If it's by design, is there a way to force an RPC call to fire immediately on the local client / host?
Are you using Unity's built-in networking?
I have no personal experience with it, so I can't say what is causing this behavior. However, you could just call a method directly ins$$anonymous$$d of relying on RPCs to do that for you.
Call the RPCs on other clients and wrap a method call in a "hasControl" statement
Yup - built in. I am doing something similar to what you suggested as a workaround (sample below), but this causes other ti$$anonymous$$g issues related to destroying / unpooling network-aware objects on the frame they execute an RPC call. If the host would receive the RPC call immediately, it could also be destroyed/disabled that frame, and the remote clients should get the RPC and subsequently disable, in that order.
[Command]
void CmdDoSomething()
{
RpcDoSomething();
DoSomethingImmediately();
}
[ClientRpc]
void RpcDoSomething()
{
// otherwise executed twice on the local client
if (!isHost)
{
DoSomethingImmediately();
}
}
void DoSomethingImmediately()
{
// do the stuff
}
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Network RCP between client server projects 0 Answers
Trying to store a variable for all clients 0 Answers