ClientRpc not working 5.4.0b24

I have a networking game in Unity Version 5.4.0b24, but when i call a [ClientRpc] function from server it doesnt work, gives an error like this:

Found no behaviour for incoming [ClientRpc:InvokeRpcRpcSetLayerWeightClient] on Player2@Owner(Clone) (UnityEngine.GameObject), the server and client should have the same NetworkBehaviour instances [netId=1].

ClientRpc [ClientRpc:InvokeRpcRpcSetLayerWeightClient] handler not found [netId=1] UnityEngine.Networking.NetworkIdentity:UNetStaticUpdate()

I have attached a NetworkIdentity, NetworkAnimation, and NetworkTransform to the game object, as well as my script below:

My script below was attached to the game object dynamically at run-time (dont know if that has anything to do with it). Also note that the gameobject in question is a UMA DYNAMIC AVATAR (an avatar created dynamically, see on in the asset store)

so that Start () method you see below is actually in the locomotion example script that UMA comes with, I just changed it to derive from NetworkBehavoiur, and added the other networking components mentioned above, and modified the locomotion script thus:

Here is my code:

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine.Networking;

public class Locomotion : NetworkBehaviour {
.....
 
void Start()
{ 
....
    setLayerWeightServer(0, 0);   // client call set animation layer weight
}

public void setLayerWeightServer(int layer, float weight)
{
   animator.SetLayerWeight(layer, weight);
   CmdSetLayerWeightClients(layer, weight);  // call to server WORKS!!
}

[Command]
public void CmdSetLayerWeightClients(int layer, float weight)
{
    RpcSetLayerWeightClient(layer, weight); // call to clients FAIL!!!!
}

// NEVER GETS CALLED
[ClientRpc]
public void RpcSetLayerWeightClient(int layer, float weight)
{
    animator.SetLayerWeight(layer, weight);
}

Anybody has any idea what is wrong???

Sorry to bump this, i am with this bug. I am now also adding UMA to my multiplayer game with dynamic instantiation, The problem still occurs. Did you resolve your problem?

alright alright alright! It's working, thank You for that, I'm marking it as an answer, but the movement I'm getting is jittery and unfortunately I've no idea why.. It's less noticeable when slowed down so I could potentially hide it as i'm only using this when time's slow, but that wouldn't really meet the "polish" level I want. Any ideas? If not, thank You anyway for sorting the basics out!

1 Answer

1

See the answer here: Why is this ClientRPC not executed? - Questions & Answers - Unity Discussions

“I was calling the ClientRpc method
before the game player objects on
clients were properly set up by
OnLobbyServerSceneLoadedForPlayer. To
fix it I just waited with calling the
ClientRpc until after the start method
was invoked on all client gameplayer
objects.”

I confirmed that something like this is the problem/solution. In my case I used OnStartLocalPlayer() in my player controller to call a Command method on the server, which in turn called an Rpc method on the clients. Trying to call Rpc methods in other ways resulted in nothing happening, probably because there were no players ready, including the local one!

To be more specific, I’m creating a multiplayer game where the map is procedurally generated by the server each session.

Player code snippet:

public override void OnStartLocalPlayer()
{
    _buildingManager = FindObjectOfType<BuildingManager>();

    _buildingManager.CmdPlayerReady();
}

BuildingManager code snippet (Thing that sets up the map):

[Command]
public void CmdPlayerReady()
{
    RpcSetupMap();
}

[ClientRpc]
public void RpcSetupMap()
{
    Debug.Log("Spawn Blocks.");
    SpawnBlocks();

    Debug.Log("Spawn Buildings.");
    SpawnBuildings();
}

In case anybody asks, I’m also using Random.InitState(Seed); to generate the same map on each client. Seed is a [SyncVar ] that gets randomly generated by the server each session.

I’m on version 5.4.0f3 Personal.

try to tweek last parameter of *Towards functions. This way you are moving 1m/s and rotatin 1 degree/s. //Moving 10m/s transform.position = Vector3.MoveTowards(transform.position, endP, Time.deltaTime * 10f); //Rotating 180 degree per sec transform.rotation = Quaternion.RotateTowards(transform.rotation, endR, Time.deltaTTime * 180f); Glad that I can help.