2
\$\begingroup\$

I have a Unity 5 client and server running. On the server a path is generated and I want the client to receive the position of each target node on this path. Following the Client RPC calls section here http://docs.unity3d.com/Manual/UNetActions.html I have created the following script:

public class AccessingTargetPos : NetworkBehaviour {


[ClientRpc]
void RpcPosFromServerToGoTo(Vector3 pos)
{
    UnityEngine.Debug.Log ("Going to ... " + pos);
}


public void PrintPath(Vector3 pos)
{
    if (isServer) 
    {
        UnityEngine.Debug.Log (pos);
        UnityEngine.Debug.Log("Send Pos ...");
        RpcPosFromServerToGoTo (pos);
        UnityEngine.Debug.Log("Sent!!");

    } 
}


}

Both the client and the server have this script, assigned to a game object. However with the above I receive the following in my console:

enter image description here

At the moment all I want is for the client to output the positions received. When I get this I'll move on. I have followed the link, where have I went wrong here?

\$\endgroup\$
1
\$\begingroup\$

My problem here was not reading the RPC calls section of http://docs.unity3d.com/Manual/UNetActions.html properly. "They can be sent from any server object with a NetworkIdentity that has been spawned." When I had the client object reading in the locations become a spawned object under Registered Spawnable Prefabs (under Spawn Info, under Network Manager Script from Unity 5) then the RPC was called. I was calling the RPC on a static object before hand, throwing up the errors seen above.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.