Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Question Even if I call RPC several times per second, does the rpc send data to the server only at the set se

Discussion in 'Netcode for GameObjects' started by youngwoocho02, Jul 9, 2022.

  1. youngwoocho02

    youngwoocho02

    Joined:
    Feb 8, 2019
    Posts:
    17
    Even if I call RPC several times per second, does the rpc send data to the server only at the set server rate?

    For example
    If a game with a server rate of 60 frames per second at 30 days receives data (such as input) every frame and calls the RPC,
    In effect, the RPC function was called 60 times
    But do you only go to 30 as much as the server rate?
    Or all 60 of them all?
     
  2. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    Rpc calls are buffered, so if you call an Rpc 60 times a second with a tick rate of thirty, then every tick two Rpc calls will be sent at once.
     
  3. youngwoocho02

    youngwoocho02

    Joined:
    Feb 8, 2019
    Posts:
    17
    Thanks for answer!
    so do I have to use things like coroutine to send rpc in right time?
     
  4. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    No, you simply cannot send information over the network between ticks. If it's absolutely essential that you do, increase the tickrate in the NetworkManager in the editor.
     
  5. youngwoocho02

    youngwoocho02

    Joined:
    Feb 8, 2019
    Posts:
    17
    Oh that's not it I just wanted to prevent input data from being over-sent from the client to the server

    Previously, it was sent hundreds of times per second depending on the frame
    Now I've limited it to 15 times using Coroutine.

    I left it because I thought it didn't matter how many times I called the RPC
    But thanks to you, I'm glad that I can prevent you from sending too much data.
     
  6. CosmoM

    CosmoM

    Joined:
    Oct 31, 2015
    Posts:
    204
    Ah, my bad – yes, if you want to send Rpc updates less frequently then a coroutine is perfect for that.
     
    youngwoocho02 likes this.
  7. gnp89

    gnp89

    Joined:
    Jun 25, 2012
    Posts:
    36
    I need to send an RPC in the OnApplicationFocus(bool focus) to notify clients when the host has lost focus.
    This is critical in a peer to peer topology, where the server is suddenly paused and needs to communicate this to all clients before that happens.

    I found this thread interesting because my scenario is experiencing this problem.
    Unfortunately increasing the tick rate is not working for me.

    I even made the OnApplicationFocus a coroutine and called a
    yield return new WaitForEndOfFrame()
    but it didn't work. I debugged this and if I add 3 wait for frames, it only prints one and the app goes to the background, without sending the RPC.

    I can't believe there's no way to work around this issue. I just need to send an RPC on demand, or make it happen somehow before the app goes to the background. Any help is deeply appreciated!
     
  8. gnp89

    gnp89

    Joined:
    Jun 25, 2012
    Posts:
    36