Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Strange RPC behaviour

Discussion in 'Scripting' started by Connor_13_, Nov 6, 2014.

  1. Connor_13_

    Connor_13_

    Joined:
    Mar 14, 2014
    Posts:
    40
    I have a script that is supposed to run 4 RPC calls using RPCMode.All. All 4 of the functions are called correctly on the local player but only 3 are called on the same player on the rest of the network. I have no idea why it is behaving this way. Here is some code...

    Code (CSharp):
    1.     protected virtual void Fire()
    2.     {
    3.                
    4.         // update firing rate
    5.         m_NextAllowedFireTime = Time.time + ProjectileFiringRate;
    6.  
    7.          //play fire sound
    8.         if (SoundFireDelay == 0.0f) {
    9.             networkView.RPC ("PlayFireSound", RPCMode.All); //PlayFireSound();
    10.         }
    11.  
    12.         // spawn projectiles
    13.         if (ProjectileSpawnDelay == 0.0f){
    14.             networkView.RPC ("SpawnProjectiles", RPCMode.All);//SpawnProjectiles();
    15.         }
    16.  
    17.         // spawn shell casing
    18.         if (ShellEjectDelay == 0.0f){
    19.             networkView.RPC ("EjectShell", RPCMode.All);//EjectShell();
    20.         }
    21.  
    22.         // show muzzle flash
    23.         if (MuzzleFlashDelay == 0.0f){
    24.             networkView.RPC ("ShowMuzzleFlash", RPCMode.All); //ShowMuzzleFlash();
    25.         }
    26.  
    27.     }
    28.  
    29.     [RPC]
    30.     protected virtual void PlayFireSound()
    31.     {
    32.         Debug.Log ("Play Sound");
    33.     }
    34.  
    35.     [RPC]
    36.     protected virtual void SpawnProjectiles()
    37.     {
    38.         Debug.Log ("Spawn Projectile");
    39.     }
    40.  
    41.     [RPC]
    42.     protected virtual void ShowMuzzleFlash()
    43.     {
    44.         Debug.Log ("Muzzle Flash");
    45.     }
    46.  
    47.     [RPC]
    48.     protected virtual void EjectShell()
    49.     {
    50.         Debug.Log ("Spawn Shell");
    51.     }
    52.  
    The RPC that doesnt fire correctly on the rest of the network is EjectShell().

    Thank you for any suggestions you have.
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    So right off the bat - comparing equality among floating point numbers is problematic. That being said - there is otherwise nothing immediately apparent in this code that would cause your issue so the problem is probably elsewhere.

    I'd also be curious to see if that set up even worked with RPCs as I'd be very surprised if inheritance worked. Just guessing but - are you overriding EjectShell in a child class and not annotating it as an RPC? Does annotating it work? Does not overriding it work?

    If you look at the network traffic in the Editor is it being sent/received correctly?
     
  3. Connor_13_

    Connor_13_

    Joined:
    Mar 14, 2014
    Posts:
    40
    Thanks for your suggestion. I turned the network debug level to full and it says
    Sent RPC call 'PlayFireSound' to all connected clients
    Sent RPC call 'SpawnProjectiles' to all connected clients
    Sent RPC call 'ShowMuzzleFlash' to all connected clients

    but it does not mention EjectShell. I searched the whole project for EjectShell and this file is the only one with such a reference.

    I still have no idea. Ill keep looking around in the project
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Is that the case when the Editor is the player sending the RPC as well as the player receiving it?
     
  5. Connor_13_

    Connor_13_

    Joined:
    Mar 14, 2014
    Posts:
    40
    It was the same both ways I believe.

    I've created a work around anyways that should work better in the future. Thanks for your help though.