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. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Rpc from Child Class won't work (and makes the game stutter)

Discussion in 'Multiplayer' started by WolfoOld, Aug 5, 2015.

  1. WolfoOld

    WolfoOld

    Joined:
    Jan 12, 2014
    Posts:
    22
    Everytime I send a ClientRpc from Server to Clients through a NPC I get this (along with it not working and the game stuttering)


    Exactly when sending ONE single RPC
    Code (CSharp):
    1.   [ClientRpc]
    2.   public void RpcSendHealth(int hp)
    3.   {
    4.       health = hp;
    5.   }
    and just calling
    Code (CSharp):
    1.  
    2.   if (isServer)
    3.       RpcSendHealth(health);
    4.  
    upon taking damage.

    I then noticed this only happens when the Rpc is situated in the Parent Class, using ONLY the Parent Class it works just fine.

    Any ideas? This is really annoying, I need to send information to players and this won't let me.
    I have a BasicAI class which contains the Rpcs and is inherited by other classes.
     
  2. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    Here's a small note I jotted down when I wanted to do something to make a network game. Hopefully this helps:

    Code (CSharp):
    1. /*
    2.     Steps to use:
    3.  
    4.     [Client -> Server] is the [Command] attribute.
    5.     Use [ClientCallback] to call a [Command] method.
    6.     Use [Command] to "sync" or give corrections to an important/useful variable.
    7.     Use [SyncVar] to "sync" the important/useful variable across all clients.
    8.     Use the important/useful variable to update other game object related properties.
    9.  
    10. */
     
  3. seanr

    seanr

    Unity Technologies

    Joined:
    Sep 22, 2014
    Posts:
    669
    try upgrading to the latest patch release
     
  4. WolfoOld

    WolfoOld

    Joined:
    Jan 12, 2014
    Posts:
    22
    It is up to date(I believe), 5.1.1f1 right?

    I found a workaround but it's kind of annoying, placing all RPCs and Commands in a separate class with no inheritance between this one and the caller(the original parent class).

    Well this was just a test, usually I'd use RPCs to make Clients run certain methods which cannot be done elseway.
     
  5. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
    It's technically 5.1.2f1. So, you need to update.
     
  6. WolfoOld

    WolfoOld

    Joined:
    Jan 12, 2014
    Posts:
    22
    How do I get the newest version then?
     
  7. asperatology

    asperatology

    Joined:
    Mar 10, 2015
    Posts:
    981
  8. WolfoOld

    WolfoOld

    Joined:
    Jan 12, 2014
    Posts:
    22
    Welp thanks a ton! I'll post as soon as I test this with the new update (unless someone else has tried already)

    Edit:
    Yep, works like a charm.
     
    Last edited: Aug 6, 2015