- Home /
Sync large amount of variables via Network
Hello Unity Answers,
I currently have a script that has a large amount of Static variables. It basically is a repository of data that controls almost everything. I am wondering if there is a simple and fast way to sync this scipt with 8 computers. There is 100ish variables, and most are strings.
Thanks, Kelhedros.
Answer by IJM · Sep 21, 2010 at 01:14 AM
Why do you need that? On 60fps, with say 250 chars per string it's ~11.5MB each second. (Download and upload)
What are you trying to do?
I can't exactly say, but it is kinda like a emulator for a certain type of machine. But the strings are used to cause other things to happen. I guess I could make another set of ints and use them as IDs or make some kind of file to store data and then set the values based on an int id. That would reduce the load on the network greatly. Or do you have a better sugestion?
Also would reliable sync only sync the changed values? Becuase I only change a few at a time.
Answer by PrimeDerektive · Jan 01, 2011 at 04:41 PM
You should look at your game and make sure these variables need to be synced (for example, if they are used to make an AI move around or something, are you sure you couldn't just do all the calculations with those variables on the server, and just sync the results to the clients?
Also, if you absolutely have to sync them, is it necessary that you sync them every frame, or could you get away with only syncing them once every second, once every half second, or even once every tenth of a second? For instance, I sync the health of my authoritative AI enemies from the server to the clients with an invokerepeating rpc every 0.25 seconds, and its about 8x less bytes/second than every frame, and the difference in gameplay is negligible.
Answer by jc_lvngstn · Mar 25, 2011 at 05:52 PM
My thoughts: I'd have a class where I call a SetValue method, which maintains the list of variables and their values. It would track each variable, and flag when its value has changed.
Then, I would have a Sync() method that sends only the values which have changed to the clients. This might or might not be what you are looking for though. If you want more info, I'd be glad to give more details.
On a side note...it personally annoys me when someone asks how to do something, and gets "Why are you trying to do this?" Guys, at least assume it's for a good reason and give an idea of how to accomplish his original question, instead of asking the OP to justify his question and just leaving it at that.