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

Networking RPC Issue..

Discussion in 'Multiplayer' started by seon, Jan 11, 2008.

  1. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    I am experiencing a very strange behavior with my RPC calls that I cant seem to get working as I would think it should work.

    Here are the chunks of script that showcase what I am doing...

    Code (csharp):
    1. function OnTriggerEnter(collision : Collider) {
    2.  
    3.      if (you are on the red team and you have hit the blue flag)
    4.          networkView.RPC("setFlag", RPCMode.All, "blue", "off", playername, team);
    5.          // have also tried RPCMode.Others
    6. }
    Code (csharp):
    1.  
    2. @RPC
    3. function setFlag(flag : String, status : String, playernum : int, team: int)
    4. {
    5.     yield;
    6.    
    7.     Debug.Log ("Turning "+flag+" flag "+status+"     "+Time.time);
    8.    
    9.     if (flag=="blue") {
    10.         if (status=="on"){
    11.             turn on blue flag
    12.         }
    13.         else if (status=="off"){
    14.             turn off blue flag
    15.         }
    16.     } else  if (flag=="red") {
    17.         if (status=="on"){
    18.             turn on red flag
    19.         }
    20.         else if (status=="off"){
    21.             turn off red flag
    22.         }
    23.     }
    24. }
    Ok, this looks pretty straight forward, and it works as expected.. sort of.

    If the server computer hits a flag, the flag on the server gets turned off, and all client computers flags get turned off. (works as expected).

    If a client hits a flag, the flag on the client and server get turned off... but ALL other clients flags don't get turned of. The RPC doesnt even get called on the other clients because my debug.log doesn't get called.

    My understanding of RPCMode.All is that everyone connected to the game gets this message.

    I am clearly missing something... anyone got any ideas?
     
  2. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    No takers?
     
  3. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    277
    Well, RPCMode.All and RPCMode.Others do work as advertised. Your code looks OK, so something else must be wrong.

    How are you testing this? In multiple editors? Deployed players? Multiple machines or all on localhost? Are you certain everyone is connected, etc? Do you have the debug level set to information in the network manager and are there any network errors or warnings on the server/clients which could shed some light on this?
     
  4. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Testing this across the LAN and WAN, on windows and Mac builds and in the editor on my machine. Yes Everyone is connected because everyone is driving around playing the game... scores are maintained, game status is maintained. All is working as it should.

    No other network errors, not other issues.

    The game is working perfectly except for this issue, and this issues is here on every situation I use it... for instance, I not only use this code to change flag states, but I also use similar functions to change the icons on top of each car so players can see the state of each car on the overview map.

    I can reproduce this problem consistently, and though I am not saying its not because of some other code somewhere in my game, I am at a loss as to where this could be, as these calls and behaviors are pretty isolated game logic wise.
     
  5. larus

    larus

    Unity Technologies

    Joined:
    Oct 12, 2007
    Posts:
    277
    Its strange that everything works except these kinds RPC calls. I've been unable to reproduce this effect, it always works on my side. If you can reproduce this in a simple scene please file a bug on it.
     
  6. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Sure will, once I get some free time. My game is still reproducing this issue.. BUT I really feel it has to be because of something else in my code.

    I will keep you posted , and thanks for getting back to me.
     
  7. digitalzombie

    digitalzombie

    Joined:
    Dec 10, 2007
    Posts:
    86
    Hi,

    I'm new but I'll take a stab because I'm looking at networking as well ...

    The doc said "Call an RPC function on all connected peers." so from your server, all of your clients are connected peers ... from your client, only the server is a connected peer. This sounds just like your experience where it works fine from the server, but only updates the local client and the server from a client.

    To solve it, I'd check if I was on a client or server, then if on a client I'd RPC some message to a generic handler that called a server side function to update its state AND RPC to all of the clients. If I was on the server, just call the server side function just mentioned.

    That sounds confusing in text, but hopefully it comes through ok!

    Tony
     
  8. seon

    seon

    Joined:
    Jan 10, 2007
    Posts:
    1,441
    Hi Tony,

    No, the RPC should be sent to all connected... I have had this confirmed by UT.

    But thanks for your help:)
     
  9. digitalzombie

    digitalzombie

    Joined:
    Dec 10, 2007
    Posts:
    86
    Oh well, I tried! :)

    Seems like 'sent to all connected' would be dependent on what is connected to the machine issuing the RPC call. I'm still just dealing with theory otherwise I'd test, but good luck and please post the solution.

    take care,

    Tony