Search Unity

ClientRPC breaks after ServerChangeScene

Discussion in 'Multiplayer' started by Matt-Cranktrain, Sep 30, 2015.

  1. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    Here's a problem I'm running into, ClientRPC's are all fine and happily running, until I run ServerChangeScene, and then they just start failing silently.

    So if I have something like this:

    Code (csharp):
    1. [ClientRpc]
    2. public void RpcPrintSomething() {
    3.   print("Something.");
    4. }
    5.  
    6. void Update() {
    7.   if (!isServer) return;
    8.   if (Input.GetKeyDown(KeyCode.A)) {
    9.     RpcPrintSomething();
    10.     print("RPC Method has (apparently) been called.");
    11.   }
    12.  
    13.   if (Input.GetKeyDown(KeyCode.S)) {
    14.     networkManager.ServerChangeScene("NewScene");
    15.   }
    16. }
    I'm able to press A and see both "Something" and "RPC Method has (apparently) been called."

    But then if I press S, and move to a new scene, and then press A, I just see "RPC Method has (apparently) been called." The RpcPrintSomething function has not run.

    No error messages, no warnings. When I hook up the debugger with a breakpoint inside the RpcPrintSomething method, it never triggers when on the new scene, it is just failing silently.

    What's going on?
     
  2. spinaljack

    spinaljack

    Joined:
    Mar 18, 2010
    Posts:
    992
    I've got this same issue, ever find a solution?
     
  3. Matt-Cranktrain

    Matt-Cranktrain

    Joined:
    Sep 10, 2013
    Posts:
    129
    I'm afraid my solution was to remove multiplayer from my game... which is hardly the workaround you are looking for!

    Given how easy it was to reproduce that issue I suppose I should have gone the proper route and reported it on the bug tracking system (if that was a thing, four years ago?) but Unity networking at the time was such a headache I just walked away from multiplayer. Sorry!
     
  4. Foestar

    Foestar

    Joined:
    Aug 12, 2013
    Posts:
    350
    Soooooo, when you go to the new scene it calls the RPC method but does nothing? This may be a dumb question but is this code on an object that is in both scenes (not destroyed, etc.)? Because if you're loading scenes and the object isn't present then it wouldn't obviously work.