- Home /
Do static variables carry values between Clients?
Well, I was just wondering, my preferred way of carrying variables between scripts is static variables. Developing a multiplayer game, just wondering... Afraid that everyone will have the same Health variable.
Answer by DavidDebnar · Feb 12, 2014 at 05:59 PM
Static variables are only shared between classes on the same client. This means that across clients, you're not gonna have the same values. Although, you shouldn't use static variables for things like health, in most cases, shouldn't use them at all unless neccessary. Use regular variables, maybe with direct references instead, or a singleton for game states.
Edit: Some resources:
Why are static variables considered evil?
When connected to a server, can other players access my static variables and/or public variables?
--David
I was wondering the same thing: is a static variable in a script in one client visible in the (instance of the) same script in another client visible? I was hoping the answer is no, because singletons are really useful... Thanks for the answer!
Your answer
![](https://koobas.hobune.stream/wayback/20220613133315im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Android device not connecting to network 0 Answers
Passing a variable from a client to server 1 Answer
000webhost master server 0 Answers
Unity networking tutorial? 6 Answers