Search code examples
unity-game-enginemultiplayerphoton

How to ensure RPC was sent successfully in Photon Unity?


I am building a multiplayer game using Photon and Unity3D engine. I am using photonView.RPC to send data and values between clients. But sometimes due to network problem, a sent RPC failed to execute in the clients.

Is there any way that I can check from the client (who sent the RPC) that the RPC was sent successfully, if not, then again sent the RPC?


Solution

  • Conceptually, the one and only way you can do that is,

    A sends the message, with a identity code (say, "321321777")

    A waits for confirmation...

    B receives the messsage

    B sends a message "I received 321321777"

    That's really all you can do. Note that this introduces the concept of a time-out. The above actually goes more like this...

    A sends the message, with a identity code (say, "321321777")

    A waits for confirmation...

    If no confirmation after (say) 0.5 seconds, send it again. Keep doing that.

    B receives the messsage. The label is 321321777

    B sends a message "I received 321321777"

    Any more copies of "321321777" received by B, B ignores it. But: if multiple "321321777" received by B, B does again send more and more confirmation messages for "321321777"

    It's worth noting that as a general rule, "video games don't work like this." Normally you just send zillions of positions (or whatever) a second, and if a few are missed - it doesn't matter.

    Don't forget too that Unity network DOES "reliable sending" for you anyways - and there's probably such a concept in "PUN".