1

I'm just about to release a game in Unity with PUN2 and having a major delay issue with RPC calls. I am updating a value every time a button is executed, this:

[PunRPC]
private void takeOnePropertyTotal()
{
    totalProperties -= 1;
}

On my side it executes immediately, but on the second and third connected computer it takes the:

totalProperties -= 1;

even MINUTES to execute, which is insane and ruins the logic of the game completely. The computers are connected in the same region even and even on the same internet connection.

Any idea why this is delayed so much?

user3337790
  • 142
  • 1
  • 7
  • 2
    Can you share the codes that calls the "takeOnePropertyTotal" ? – Hikari Nov 30 '22 at 08:22
  • @Hikari Sure: It's in the update and is controlled via a bool: `[PunRPC] void Update(){ if (updateValidator == true) { view.RPC("takeOnePropertyTotal", RpcTarget.All); } }` – user3337790 Nov 30 '22 at 08:33
  • RPC, message queuing and other guaranteed forms of communications are a poor design choice in games due to automatic-retries which just delays things making the message arrive too late. It's better to use streaming whereby if something is lost it will be replaced by a newer up-to-date packet. Thats why you would typically just use UDP. –  Nov 30 '22 at 08:35
  • _"`[PunRPC] void Update(){ if (updateValidator == true) { view.RPC(...`_ - so you are piling up RPC calls at a rate of typically 60 times per second! –  Nov 30 '22 at 08:37
  • @Deleted oh.... Dang, i see what you mean. So should avoid using the call in the Update method right? Even thought, i disable the bool right after the call is made? – user3337790 Nov 30 '22 at 08:38
  • 1
    _"So should avoid using the call in the Update method right?"_ - it's OK to put it in `Update()`, it kind of makes sense to do so, however you might want to put a guard statement in there like `if (doINeedToSendAnUpdate) { DoRPCStuff(); doINeedToSendAnUpdate = false; }` to control _how many_ are sent per second. That or maybe send updates every 100 m/s or whatever your game's _tick rate_ might be by looking at `deltaTime`. –  Nov 30 '22 at 09:02
  • 1
    @Deleted i did what you said and made another controller to prevent more than 1 call being send. Works now like intended. Thank you. If you post this as an answer, i will upvote it if you want as it solved my issue. Thanks again. – user3337790 Nov 30 '22 at 10:14
  • 1
    Great to hear! Thanks. See below. –  Nov 30 '22 at 10:19

1 Answers1

1

This is a summary of my comments beneath the question


OP:

It's in the update and is controlled via a bool

[PunRPC] void Update()
{ 
    if (updateValidator == true) 
    {
        view.RPC("takeOnePropertyTotal", RpcTarget.All); 
    } 
} 

So you are piling up RPC calls at a rate of typically 60 times per second!

It's OK to put it in Update(), it kind of makes sense to do so, however you might want to put a guard statement in there like

if (doINeedToSendAnUpdate) {  DoRPCStuff(); doINeedToSendAnUpdate = false; } 

...to control how many are sent per second.

That or maybe send updates every 100 ms or whatever your game's tick rate might be by looking at deltaTime.