- Home /
What is the size of a float vs the size of a Vector3 over a network(in Bytes)?
Im making a (Most unique) shooter in unity, but when i fire it does an update setting a vector three, and it bumps up my 600 bytes a second to nearly 1200 byes a sec. I know this is low but how would I fix that? I would like to know if sending floats in more efficient. Or what about a 20 long string? which of the three is most efficient? I know I could test this but its on a small scale and I dont have a big scale yet.
Answer by Bunny83 · Nov 15, 2014 at 04:12 PM
A single float value has 4 bytes. Since a vector3 contains 3 floats it's of course 3*4 == 12 bytes. A string would probably way worse as one character is usually encoded as 16 bit unicode character. So each character will have 2 bytes and an additional length of usually 4 bytes (1 integer) for the string itself.
Since that's all you have provided that's all i can answer.
I dont nderstand why my code generates 600+ more bytes rather than 12(I fire ten tiems a sec) lemme post code
using UnityEngine;
using System.Collections;
public class GunScript : $$anonymous$$onoBehaviour {
public int $$anonymous$$odeFire = 0;
public float Firespeed;
public RaycastHit Hit;
public LineRenderer Rendy;
public Camera Cam;
public int Damage = 20;
public float $$anonymous$$odifier;
public AudioSource PlaySound;
// Use this for initialization
void TurnBulletOff(){
networkView.RPC("RPCFire",RPC$$anonymous$$ode.AllBuffered,transform.position);
}
void Increment(){
Fire();
}
[RPC]
void RPCFire(Vector3 Pos ){
Rendy.SetPosition(0,transform.position);
Rendy.SetPosition (1, Pos);
}
void Fire(){
if (Physics.Raycast (Cam.camera.ScreenPointToRay(Input.mousePosition), out Hit, 3000)) {
PlaySound.Play();
CancelInvoke("TurnBulletOff");
Invoke("TurnBulletOff",.5f);
networkView.RPC("RPCFire",RPC$$anonymous$$ode.AllBuffered,Hit.point);
print(Hit.point);
if(Hit.transform.tag == "Player"){
int HealthLower = Hit.transform.parent.transform.GetComponent<HealthScript>().Health;
int SetDam = Random.Range(Damage - 5, Damage + 5);
int LowHealth = HealthLower - SetDam;
//
Hit.transform.parent.transform.networkView.RPC("SetHealth",RPC$$anonymous$$ode.AllBuffered, LowHealth);
}
}
}
// Update is called once per frame
void Update () {
if (networkView.is$$anonymous$$ine) {
if($$anonymous$$odeFire == 0){
if(Input.Get$$anonymous$$ouseButtonDown(0)){
Fire();
}
}
if($$anonymous$$odeFire == 1){
if(Input.Get$$anonymous$$ouseButtonDown(0)){
InvokeRepeating("Increment",0.05f, Firespeed);
}
if(Input.Get$$anonymous$$ouseButtonUp(0)){
CancelInvoke("Increment");
}
}
}
}
}
@applejuices: Well, you send a RPC. This call has of course additional information to transmit, like what method it should call on the other side, the mode / receiver, count and type of parameters and the parameters itself.
Answer by Owen-Reynolds · Nov 15, 2014 at 05:26 PM
That 600 to 1200 bytes is the network traffic? Isn't that "raw" bytes, including all the headers? For example, each RPC also includes the name of the sending function, and probably a timeStamp. What sort of RPC was giving you the 600 bytes figure?
If your same RPC sent one extra Vector3, I imagine you'd see just a small increase. How much traffic does an RPC with no parms generate?
Your answer
Follow this Question
Related Questions
How to send bytes data between two different build 1 Answer
Unity Web Request 2 Answers
Upgrading from Legacy Networking to new networking 2019.1 0 Answers
Unity knowing if connected to cellular not WiFi 0 Answers
How do I fix the problem with animator.Play() using Mirror Network in Unity. 0 Answers