- Home /
Intense CPU usage when running networking code on Editor only
I'm trying to understand networking, so I wrote up a very rudimentary client-server interaction with RPC calls. I have an issue with running this little test on the editor, but the standalone player handles it perfectly fine.
Setup: There is only one scene, it contains a cube that can be selected and moved on a plane through mouse input, like an RTS game. The cube movement is a Vector3.Lerp from its current position to a target position that can be set.
As it stands, if I run both client and server instances with the standalone Unity player, it's fine. The client is a little choppy (I believe due to a lack of client-side prediction, correct me if I'm wrong), the server runs completely smooth, and both instances take no more than 5% CPU.
However, if I try to run either side on the Unity editor, the editor eats up an entire core and is noticeably choppier. The other side is fine as above, though if I'm running the server on the editor the client suffers even more, so I'm inclined to think it's a performance issue in the editor.
I don't think my network setup is at fault. I setup both ends to 127.0.0.1:25001, and the server reports that it receives 1 connection from 1 client, etc.
Here's my code for the cube's movement. It's the only place where I have RPC calls in the project. I've taken steps to limit execution to only where it's relevant, but I don't see any improvement.
public class MoveUnit : MonoBehaviour {
private Vector3 targetLocation;
void Awake()
{
targetLocation = transform.position;
}
void Update()
{
if(Network.peerType == NetworkPeerType.Client)
{
enabled = false;
}
else if(Network.peerType == NetworkPeerType.Server)
{
transform.position = Vector3.Lerp(transform.position, targetLocation, Time.deltaTime);
}
}
// Called by input handler sripts. Delivers a new target position for
// this object to move towards.
void MoveOrder(Vector3 newPosition)
{
if(Network.peerType == NetworkPeerType.Client)
{
networkView.RPC("UpdateLocationServer", RPCMode.Server, newPosition);
}
}
// Server-side, receives a new target position for this object to
// move towards.
[RPC]
void UpdateLocationServer(Vector3 newPosition)
{
if (Network.peerType == NetworkPeerType.Server)
{
targetLocation = newPosition;
}
}
}
For the obvious troubleshooting: My quality setup involves VSync at every VBlank (without it even the standalone player suffers). The NetworkManager has Sendrate at 30, with logging disabled. There is no logging going on at all.
I have reimported everything once with no noticeable improvement.
I haven't downloaded any packages to Unity besides an official demo.
I don't have Unity Pro, so I can't make use of the performance profiler.
Does anything here look wrong to you? I'd appreciate any ideas on how I can troubleshoot this.
Thanks!
Edit: The problems seem to have disappeared after a reboot (not simply restarting Unity, apparently). While I'm disappointed that a bunch of system standbys would cause something like this, I'd still appreciate any tips on my setup above that can be improved.
If you want tips, go to the forums. Since this is now fixed, please close the question :)