Search Unity

Buffered RPCs

Discussion in 'Multiplayer' started by will_w, May 13, 2009.

  1. will_w

    will_w

    Joined:
    Feb 20, 2008
    Posts:
    56
    My networked game seems to be working ok, but I have a few glitches. Need some help pointing me in the right direction. I've done quite a bit of reading and trying on my own.

    Basically its a pretty simple problem:

    When a character fires a rocket, the rocket is network.instantiated across all clients. I want to use an RPCMode.All I believe as should not add it to the buffer.

    Although I use the RPCMode.All , its still being added to the buffer when it is network.instantiated.

    Do I need to instantiate it locally and remotely instead of using network.instantiate ?

    Also, is there a way to use the RPCMode enumerator outside of the RPC call? something like network.RPCMode.All

    Last question, is there an easy way to call the RPC only on the local player? Its easy enough not to make it an RPC, then its callable locally only - but then I can't use RPCMode to limit the buffer.

    So I guess another way of saying it, is:
    Is there a way to remove a specific RPC from the buffer?

    To summarize the problem here's an example:

    Player 1 fires a bunch of rockets at Player 2. The rockets instantiate fine, collide fine, and destroy themselves fine using network.destroy. But if Player 1 disconnects, then rejoins the same fight, all those missiles he already fired will respawn upon connection.

    Thanks in advance. I'm pretty sure I'm missing some little but very important element in the equation.
     
  2. BearishSun

    BearishSun

    Joined:
    Dec 1, 2008
    Posts:
    175
    You really shouldn't be using network instantiate for rockets. They shouldn't be buffered.

    Instead try making a function like this:

    Code (csharp):
    1. [RPC]
    2. void FireRocket(Vector3 From, Vector3 To)
    3. {
    4.   Instantiate(...)
    5. }
    and then just do

    Code (csharp):
    1. networkView.RPC("FireRocket", RPCMode.All, From, To)