- Home /
[Solved]Send rate of rpc is slow even if Network.sendRate = 15;
void Start ()
{
InvokeRepeating ("Rate", 0, 2.5f);
}
void Rate()
{
Network.sendRate = 15;
}
Ive tried that, it still didnt work, i have this script that sends an rpc telling where a player is everytime the Vector3 position is different from last position. And it does sends, but instead it sends the rpc twice per second when testing on 2 pc's even on same machine. Using a Mac OS X maverick with U3D free version
Heres the MovementUpdate.cs ( similar to how M2H does it )
using UnityEngine;
using System.Collections;
public class MovementUpdate : MonoBehaviour
{
private Vector3 lastPosition;
private Quaternion lastRotation;
private Transform myTransform;
void Start ()
{
if(networkView.isMine == true)
{
myTransform = transform;
networkView.RPC("Sync", RPCMode.Others,myTransform.position, myTransform.rotation);
}
else
{
enabled = false;
}
}
void OnPlayerConnected(NetworkPlayer player)
{
networkView.RPC("Sync", player,myTransform.position, myTransform.rotation);
}
void Update ()
{
if(Vector3.Distance(myTransform.position, lastPosition) >= 0.1f)
{
lastPosition = myTransform.position;
networkView.RPC("Sync", RPCMode.Others, myTransform.position, myTransform.rotation);
}
if(Quaternion.Angle(myTransform.rotation, lastRotation) >= 1)
{
lastRotation = myTransform.rotation;
networkView.RPC("Sync", RPCMode.Others,myTransform.position, myTransform.rotation);
}
}
[RPC]
void Sync (Vector3 newPosition, Quaternion newRotation)
{
transform.position = newPosition;
transform.rotation = newRotation;
}
}
Basicly, it should send the RPC called Sync everytime the player moves more than 0.1 units or rotates 1 degree. It does it, but twice per second.
Heres a video : LINK - in the video you can see what i mean, and when the red player health reaches 0, there was a delay.
Why would you want to set the send rate ever 2.5
seconds?
Firstly variables don't change unless you change them, so why set it more than once?
Secondly if you want it to stay the same just change it in the network settings of your project and be done with it
because even if i do change it every 2.5 seconds, it doesnt change the send rate, ive checked it in the Edit>Networking and the Sendrate is set to 15, still no luck. Is it because im using U3D 4.3.2?
If it's set to 15 in the project settings why are you setting it again in the scripts? Why post that script if you're not having a problem changing the send-rate, but rather a problem with sending the data. It would be infinitely more useful if you posted how you're sending the data, rather than how you're (not) changing the send-rate.
i dont know why the send rate is so slow, that it sends only 2 times per second ( the rpcs ). When the player i control moves, it moves fine with 60FPS, on the other screens, the position updates only twice per sec, and same goes to shooting, sending messages and updating a text over RPC. And i posted that script to show that ive tried forcefuly change the sendRate
Answer by Kiloblargh · Dec 27, 2013 at 07:55 PM
If you are using RPCs to update the position, sendRate should not affect that. Network.sendRate controls how often it updates if you are using automatic position synch from the NetworkView's observed property. There is probably something wrong with how you are sending the RPC or checking when to send it, in the relevant part of the script that you didn't post.
I'm not too sure that sendrate doesn't affect RPC's. By all means, Unity could put all your RPC calls into the same packet every 15th of a second. With the amount of RPC gettings sent in my project that is most likely what is actually happening?
RPCs are sent when you send them. Post the part of your script that sends the RPCs. But I watched the video and even if you fix your RPC code to send more often, it will still look awfully jerky for the client if you are moving the player from one discreet position to another every time an RPC arrives. Ins$$anonymous$$d you should be moving it every frame on the client side and using the received position to smoothly correct from the predicted position toward the actual position.
Ok, your script looks like it should work, I don't know what the problem is. Put a` Debug.Log` message in the if()
after networkView.RPC and another one in the RPC function and see how often it is getting called on the server side.
it does it fine, every time i move 0.1 units or rotate a degree, it does everything fine.
Your answer
Follow this Question
Related Questions
Send RPC in 2 scene 0 Answers
RPC calls client to server Errors 1 Answer
Getting rotation to work on client 1 Answer
Network RPC 1 Answer
Does Unity merge RPC calls into one packet per tick? 0 Answers