Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jan 28, 2017 at 11:36 AM by Logan76667 for the following reason:

The question is answered, right answer was accepted

avatar image
1
Question by Logan76667 · Jan 26, 2017 at 02:49 AM · networkingnetworksynchronizationsync

How fast do Syncvars synchronize?

I'm making an online 2-player Trading Card game.

At the start of the actual cardgame scene, the GameController sends an Rpc to both clients, asking them to send it their playerName and decklists, which are both saved locally as a simple string.

My Question is basically, when

 myGui.SetPlayerData(resourceContainer.GetPlayerData());

is in the code, right below

 clientController.RpcClientSendPlayerData();

will the function GetPlayerData() already return the data that is sent by the clients when RpcClientSendPlayerData is called?

Are Syncvards synched immidiately? Or will program wait until everything is synched before calling RpcClientSendPlayerData ?

Code Extracts:

(GameController, Server-only)

     clientController.RpcClientSendPlayerData();
     myGui.SetPlayerData(ResourceContainer.GetPlayerData());

(ClientController)

 [ClientRpc]
 public void RpcClientSendPlayerData()
 {
     localPlayer.CmdPlayerSendPlayerData();
 }

(Script on the local player, local player authority)

 [Command]
 public void CmdPlayerSendPlayerData()
 {
         resourceContainer.SetPlayerData("host", myName, myDeckString);
 }

(ResourceContainer)

 [SyncVar]
 string hostName;
 [SyncVar]
 string hostDeckString;

 public void SetPlayerData(string player, string playerName, string deckString)
 {
     if (player == "host")
     {
         hostName = playerName;
         hostDeckString = deckString;
     }
 }


Thanks in advance!

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Bunny83 · Jan 26, 2017 at 05:26 AM

I have barely worked with the new networking system. However syncvars are just "syntactical sugar". Unity actually creates RPC methods to sync the content of those variables when you set them. So in your case i would say; no, you won't see the update unless you have a damn fast connection and a slow PC ^^.

To address your question "How fast do Syncvars synchronize?", well, how fast does a car go? The answer is: it depends on the car and on the road it drives on ^^.

However you can specify a "hook" in your syncvar attribute. Basically just the name of a method that should be executed whenever the value of the syncvar has changed on the client.

Something like that:

 [SyncVar(hook="OnHostNameChanged")]
 string hostName;
 
 void OnHostNameChanged()
 {
     // "hostName" has just received an update
 }

Comment
Add comment · Show 3 · 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
avatar image Logan76667 · Jan 26, 2017 at 10:40 AM 0
Share

Okay, so it is as I expected, thanks bunny!

You say it depends on the car and the road, and that makes sense of course, but what kind of range could I expect, anything between 0.1 and 1 seconds, or longer?

The game will be on android, and 3 instances of it will run over a local hotspot I create with my own phone probably, the 3 devices are relatively old, between three and six years old.

If you could give me a general idea of what kind of delay I should expect, that would be appreciated!

avatar image Bunny83 Logan76667 · Jan 28, 2017 at 06:29 AM 1
Share

The range you can expect can reach from 1ms to "infinity"(if the connection is interrupted). The latency depends completely on the connection. If someone in europe is connected to someone in the usa you can expect at least 25ms+ as that's the time a signal would take at the speed of light. In most cases it's way higher since there will be several routing nodes in between. Common values would be 70ms - 300ms. Though it's never guaranteed.

If two people are on the same local network you usually get latencies below 10ms, usually even < 2ms. Though wlan is more vulnerable to interference and generally a little bit slower, though in most cases you wouldn't see any difference.

$$anonymous$$obile internet connections (GS$$anonymous$$ / GPRS, U$$anonymous$$TS, LTE, ...) have in general a slightly higher latency.

avatar image Logan76667 Bunny83 · Jan 28, 2017 at 11:36 AM 0
Share

okay, that's also somewhere in range of what I expected I've introduced a fixed two second delay, on top of the 5 second delay I allow for both players connecting to and loading the scene. Ideally something would happen on each players' screen for the duration, but for now there's a loading screen.

Thanks again bunny, this question can be closed :)

Follow this Question

Answers Answers and Comments

101 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

SyncVar works with disabled components? 0 Answers

[SyncVar] protect Cheat Engine 0 Answers

Networking Sync SetActive Not Working 0 Answers

Synchronizing game object across clients 2 Answers

UNET : SyncVar value not updating, hooks firing 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