Search Unity

Deal with Cmd and Rpc functions delay.

Discussion in 'Multiplayer' started by Sahkan, Dec 2, 2015.

  1. Sahkan

    Sahkan

    Joined:
    Mar 3, 2013
    Posts:
    204
    I'v noticed when I'm running functions like Cmd and Rpc they won't execute on the same frame they called in.

    example:

    Code (CSharp):
    1. int x = 1;
    2.  
    3. void foo()
    4. {
    5.     Rpc_ChangeValue();
    6.     print(x) //prints 1
    7. }
    8.  
    9. [ClientRpc]
    10. Rpc_ChangeValue()
    11. {
    12.     x=2;
    13. }
    14.  
    If this is the case, is there a way to deal with it with a coroutine?

    something like:

    Code (CSharp):
    1. IEnumerator foonumerator()
    2. {
    3.     yield Rpc_ChangeValue(); //If it would work it would be great.
    4.     print(x);
    5. }
    For now i'm just adding using a bool variable like"networkTrafficInProgress" and wait till the other side change it's value and then continue, However it adds code to the overall script.
     
    Last edited: Dec 2, 2015
  2. DRRosen3

    DRRosen3

    Joined:
    Jan 30, 2014
    Posts:
    683
    You'll never get Commands and ClientRpcs to execute on the same frame. Commands happen on the server which will ALWAYS be a step or two ahead of connected clients.