2
\$\begingroup\$

I have a client server scenario, just a player moving about on the client and he moves about on the server using the built in networking provided in Unity 5.

I have my client scene running in the editor and was playing about with the Network Transform script values, more specifically the Network Send Rate.

  • Setting this Value to 29 (its highest), the movement on the server is almost smooth.
  • Setting this value to 1 and the movement on the server is very laggy, as I expected.
  • However, if I set the network send rate to 0 on the client, I expected it not to move at all on the server, but it moves and a lot smoother than the value 29.

Why is it, when the network send rate is set to 0, that my character still moves on the server?

\$\endgroup\$
2
  • \$\begingroup\$ Maybe 0 is not a valid value and is clipped to 1? \$\endgroup\$ Commented Aug 24, 2015 at 11:52
  • \$\begingroup\$ Nah i don't think so. When the value is at 1 the movement on the server is very choppy, but at 0 its very smooth, i thought it shouldn't be moving at 0, something else must be taking over. This happens from character movement, doesn't seem to affect objects. \$\endgroup\$ Commented Aug 24, 2015 at 12:44

2 Answers 2

1
\$\begingroup\$

It looks like this API is set up so that a send rate of 0 means "on demand".

If you're continually moving an object that's been set to, say, 10 network updates per second, those transform changes get recorded but not sent right away. Then, when the next 10 Hz window comes around, the latest value is picked up and sent across the network.

But if you've set this value to 0, then there's no regular process checking in on the transform value to send it at regular intervals. So transform changes could get missed entirely.

To prevent changes from not being replicated at all, if a NetworkTransform that's not scheduled for regular transform updates moves, Unity sends the message right away to ensure that change isn't lost.

Since the Unity docs say to use this for objects that don't move after being created, this should be rare:

Property Function
Network Send Rate (seconds) Set the number of network updates per second. You can set this slider to 0 for GameObjects that do not need to update after being created, like non-interactive effects generated by a player (for example, a dust cloud left behind that the player cannot interact with).

Basically this should ensure that a late fix-up to its position after spawning isn't missed. Or if the object occasionally has to be swapped to a new location, you only pay overhead cost once on each teleport, rather than periodically as long as the object exists.

Based on the documentation quoted above, you should not set this value to zero on an object that moves continuously. As you observe, that can trigger an effectively unlimited send rate (say, once per display frame / Update() call), which could quickly eat into your bandwidth budget at high framerates.

\$\endgroup\$
0
\$\begingroup\$

This might be because your movement script doesn't specify where to execute the code, so when you input something, the code is executed on the server.

Make sure your movement code has an if(isLocalPlayer) check:

private void Update() { if (!isLocalPlayer) { return; //this checks if the code is not running on the local instance of the game // if it isn't, it stops executing what's next } //Your Code here } 
\$\endgroup\$

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.