Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by dsull · Jul 21, 2015 at 05:46 AM · c#unity 5networkingmultiplayer-networking

Can I see how many bytes are being sent by a particular SyncVar variable?

I've been experimenting with sending my information in two ways.

  1. The first way is to create a struct and put the [SyncVar] tag on it.

  2. The second way is to convert the 'would-be' struct into a string and [SyncVar] on a string. Basically a Vector3 would turn into something like, "1.2343\t5.2634\t9.23456" which I would then rebuild by manually parsing. Realistically there would be more than just a Vector3, but hopefully you get the idea

Really, all I want to know is which way actually sends less information, but I can't find a way to do this. The Unity profiler doesn't have the actual bytes, and NetworkServer.GetStatsIn/Out doesn't do anything. I'm also running it on my localhost and I don't know how to capture that information with programs like Wireshark.

Question: How can I measure the amount of bytes being sent by a SyncVar, OR Would my ghetto string method be smaller than syncing actual Vector3/Quaternion/floats/doubles/etc since it's all on a single variable?

Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image meat5000 ♦ · Jul 21, 2015 at 02:43 AM 0
Share

I think if theres anything to be had its in here.

The maximum number of bytes will not change given the amount of memory required for that data type and the max send interval. Also take in to account that a SyncVar registers changes and does not poll. I do believe that it only likes basic data-types and so will likely not work on a Struct.

There is a SyncListStruct but its not an attribute, its a class.

avatar image dsull · Jul 21, 2015 at 05:12 AM 0
Share

I tried it with a struct and it worked fine. I passed this struct through.

 public struct PosRot$$anonymous$$odel {
     public Vector3 Pos;
     public Quaternion Rot;
     public double Timestamp;
     public PosRot$$anonymous$$odel(Vector3 Pos, Quaternion Rot, double Timestamp){
         this.Pos = Pos;
         this.Rot = Rot;
         this.Timestamp = Timestamp;
     }
 }

The class script I used was

 using UnityEngine;
 using UnityEngine.Networking;
 using System.Collections;
 
 [NetworkSettings (channel = 0, sendInterval = 0.1f)]
 public class NetworkSyncPosRotStruct : NetworkBehaviour {
     
     [SyncVar (hook = "Sync$$anonymous$$essage")]
     private PosRot$$anonymous$$odel $$anonymous$$essage = new PosRot$$anonymous$$odel();
 
     void FixedUpdate(){
         var message = new PosRot$$anonymous$$odel (this.transform.position, this.transform.rotation, Network.time);
         this.Transmit$$anonymous$$essage (message);
     }
 
     public virtual bool TransmitCondition(){
         return this.isLocalPlayer;
     }
 
     [Command]
     protected virtual void Cmd_Trasmit$$anonymous$$essageFromClientToServer(PosRot$$anonymous$$odel model){
         this.$$anonymous$$essage = model;
     }
     
     [ClientCallback]
     protected virtual void Transmit$$anonymous$$essage(PosRot$$anonymous$$odel model){
         if(this.isLocalPlayer){
             this.Cmd_Trasmit$$anonymous$$essageFromClientToServer(model);
         }
     }
 
     [Client]
     protected virtual void Sync$$anonymous$$essage(PosRot$$anonymous$$odel message){
         this.$$anonymous$$essage = message;
     }
     
     ///@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     ///@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     ///@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
     ///@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
 
     public float LerpRate = 5f;
     
     // Update is called once per frame
     void Update () {
         if (!this.isLocalPlayer) {
             this.LerpPositionRotation ();
         }
     }
     
     void LerpPositionRotation(){
         this.transform.position = Vector3.Lerp (this.transform.position, this.$$anonymous$$essage.Pos, LerpRate);
         this.transform.rotation = Quaternion.Lerp (this.transform.rotation, this.$$anonymous$$essage.Rot, LerpRate);
     }
 }


I tried NetworkTransport.GetPacketReceivedRate, but I keep getting 50 whether I have 1 script or 2 sending messages so I figure I'm doing it wrong.

 [Server]
     void Update(){
         byte e;
         int r = NetworkTransport.GetPacketReceivedRate(0,
                                                        1, 
                                                        out e);
         byte e2;
         int r2 = NetworkTransport.GetPacketReceivedRate(0,
                                                         0, 
                                                         out e2);
         byte e3;
         int r3 = NetworkTransport.GetPacketReceivedRate(0,
                                                         2, 
                                                         out e3);
         Debug.Log (r + "-" + e + "\n" + r2 + "-" + e2+ "\n" + r3 + "-" + e3);
     }

avatar image dsull · Jul 21, 2015 at 05:35 AM 0
Share

I replaced GetPacketReceivedRate with GetPacketSentRate and got 16-20 bytes per second for each script, regardless of whether I was only sending a single int or whether I was sending a struct with a Vector3/Quaternion/double. So I assume that both functions aren't telling me what's going on.

 using UnityEngine;
 using UnityEngine.Networking;
 using System.Collections;
 
 [NetworkSettings (channel = 0, sendInterval = 0.1f)]
 public class NetworkNothing : NetworkBehaviour {
     
     [SyncVar (hook = "SyncInt")]
     private int $$anonymous$$essage;
     
     void FixedUpdate(){
         var message = Random.Range(1,10000);
         this.Transmit$$anonymous$$essage (message);
     }
     
     public virtual bool TransmitCondition(){
         return this.isLocalPlayer;
     }
     
     [Command]
     protected virtual void Cmd_Trasmit$$anonymous$$essageFromClientToServer(int model){
         this.$$anonymous$$essage = model;
     }
     
     [ClientCallback]
     protected virtual void Transmit$$anonymous$$essage(int model){
         if(this.isLocalPlayer){
             this.Cmd_Trasmit$$anonymous$$essageFromClientToServer(model);
         }
     }
     
     [Client]
     protected virtual void SyncInt(int message){
         this.$$anonymous$$essage = message;
     }
 
 }
avatar image nisovin · Jul 21, 2015 at 07:00 AM 1
Share

I don't actually know the answer, but I can make a guess. Floats take up 4 bytes each, and a Vector3 has three floats, for a total of 12 bytes. Strings take up two bytes per character (I believe), which means your example string, with 21 characters, takes up 42 bytes. Unless the Vector3 has much higher overhead, I would expect it to be more efficient.

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by dsull · Jul 22, 2015 at 09:28 AM

While I haven't technically found an answer on how to measure the amount of information being sent, I've decided to use a simple approach suggested by Nisovin to just measure the size of objects being synced by their fields and estimate using that.

Quote:

I don't actually know the answer, but I can make a guess. Floats take up 4 bytes each, and a Vector3 has three floats, for a total of 12 bytes. Strings take up two bytes per character (I believe), which means your example string, with 21 characters, takes up 42 bytes. Unless the Vector3 has much higher overhead, I would expect it to be more efficient.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Multiple NetworkBehaviours with the same SyncVar hook not working 1 Answer

Loading spawned prefabs upon connecting to server? 1 Answer

Re-hosting a Match in unity creates a bunch of random errors 1 Answer

Mirror: How to have the player object active before connecting to spawn it. 1 Answer

Hosting my multiplayer game 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges