Hi,
I’m writing a simple custom Network transform that has the server sending it’s position to the client, where it is cached and then interpolated between the latest position received from the server and previous ones (using Valve’s multiplayer paradigm.) I’m running into a problem with RPC calls, however, where it seems they are all buffered and then sent as a group, rather than individually. I wrote up some super simple test code to see what was going on:
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class NetPrefabTest : MonoBehaviour
{
[SerializeField]
GameObject playerFab;
NetworkClient client;
ConnectionConfig config;
void Awake()
{
config = new ConnectionConfig();
config.AddChannel(QosType.StateUpdate);
}
void InitializeClient()
{
ClientScene.RegisterPrefab(playerFab);
client = new NetworkClient();
client.Configure(config, 8);
client.Connect(inputHost, 7777);
}
void InitializeServer()
{
NetworkServer.Configure(config, 8);
NetworkServer.Listen(7777);
NetworkServer.RegisterHandler(MsgType.Connect, OnServerConnect);
}
void OnServerConnect(NetworkMessage netMsg)
{
NetworkServer.SetClientReady(netMsg.conn);
GameObject p = Instantiate(playerFab, Vector3.zero, Quaternion.identity) as GameObject;
p.GetComponent<NetPlayerMover>().playerConnectionId = netMsg.conn.connectionId;
NetworkServer.Spawn(p);
}
string inputHost = "localhost";
void OnGUI()
{
if (!NetworkServer.active)
{
if (GUI.Button(new Rect(400, 20, 200, 20), "Init Server"))
{
InitializeServer();
}
}
if (client == null || !client.isConnected)
{
if (GUI.Button(new Rect(100, 20, 200, 20), "Client Connect"))
{
InitializeClient();
}
inputHost = GUI.TextField(new Rect(100, 60, 200, 20), inputHost);
}
}
}
The instantiated prefab has just this attached.
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class NetRPCTest : NetworkBehaviour
{
int i = 0;
void Update()
{
if (isServer)
{
RpcMessageTest(i);
i++;
}
}
[ClientRpc(channel=0)]
void RpcMessageTest(int index)
{
if (!isServer)
Debug.Log(string.Format("{0}: {1}", index, Time.time));
}
}
I get all the messages in order, but I usually get a grouping of about 4-5 identical timestamps. I was under the impression that the StateUpdate QoS was intended to just send a single message, rather than buffering them. Is there a way to achieve this? I can’t seem to find a global control for the network send rate, since as far as I can tell the Network->Send Rate value (in the project settings) only applies to the old Networking.
Thanks for any help,
Erik
