RPC Invoke Order

Was wondering what triggers the next RPC to run on a client?

For example, if you had two RPCs:
  1. RPC1: Starts a coroutine and yields for it to finish. This coroutine loads a model into the scene but does it over a number of frames.
  2. RPC2: Calls a void method that runs in one frame.

What seems to happen is that the methods get invoked in incorrect order; RPC2 gets called before RPC1 finishes. What invokes the next RPC in the RPC queue is my question?

Comments

  • talothman
    talothman
    edited June 2018
    From looking into PUN's code, coroutine RPCs are started using StartCoroutine and then the next buffered RPC in the RPC queue is called. This means that RPC2 will then run right after StartCoroutine(RPC1) gets called and ends up running before RPC1 is finished, which is the cause of my issue. Any suggestions on how to handle this situation? I need RPC2, which is not a coroutine, to run after RPC1 has finished.

    For reference, here is the PUN code that iterates over the buffered RPCs and invokes them, NetworkPeer.cs 2881:
    
    object result = mInfo.Invoke((object)monob, inMethodParameters);
    if (PhotonNetwork.StartRpcsAsCoroutine && mInfo.ReturnType == typeof(IEnumerator))
    {
        monob.StartCoroutine((IEnumerator)result);
    }
    
  • marmik
    marmik
    edited July 2018
    http://doc-api.photonengine.com/en/PUN/current/general.html

    In the above documentation, under "Timing RPCs and Loading Levels", the following should help:

    A typical cause for lost RPCs is when clients load and set up levels. One client is faster or in the room for a longer time and sends important RPCs for objects that are not yet loaded on the other clients. The same happens when RPCs are buffered.

    The solution is to pause the message queue, during scene loading. This code shows how how you can do it:
    
    private IEnumerator MoveToGameScene()
    {
        // Temporary disable processing of futher network messages
        PhotonNetwork.isMessageQueueRunning = false;
        Application.LoadLevel(levelName);
    }
    
    Alternatively you can use PhotonNetwork.LoadLevel. It temporarily disables the message queue as well.

    I don't know how to fix the weird formatting, but use PhotonNetwork.isMessageQueueRunning to pause or resume the message queue.
  • This solved my issue, thanks.