When connected to a server, can other players access my static variables and/or public variables?

1.When I connect to a server and I have a few objects in my scene (NOT network instantiated) and I look them up using GameObject.Find(), is there a chance I grab someone ELSE’s object that isn’t mine?

2.Also how do static variables work across networks inside of the same scripts. If I set my character’s hair color to red in my menu scene, but then load up the game scene and access MenuScript.hairColor, will other players on the network be able to access that red color or will they access whatever color they picked?

3.As of right now when players connect to my server, players view other players with the same material as themselves. (If I pick red, all players are red while on their screen everyone is blue because they picked blue.) Why does this occur? does this have to do with me using static variables to store the player’s chosen color?

If you have a solid understanding of how networking works please share your knowledge! When players connect to the server I call an RPC function called UpdateAppearance() that is buffered and sent to all. this function is attached to the player and changes it’s color based on the variable of their chosen color. But everyone ends up viewing their own color on everyone instead of whatever color other players picked.


The programs on different machines may have the same code, but they count as completely different programs. Like two people playing their own copies of (single player) CutTheSnake 2.6.1. They will never share variables unless you do something special in code to make that happen.

An RPC function is that special something. It sends a message to the other machine saying something like “hi, I’m sending this for redDog(clone) with ID:346. You should also have a redDog(clone) ID:346 over there. If you get this, could you set iStatus to 7?”

The other magic is Unity will auto-send network messages (basically RPCs) to copy position, rotation … of “network spawned” transforms. But that’s all it does – can’t be extended to auto-copy any other properties or script vars. You have to RPC those. If they change infrequently, you can send them only when they change.

A clever trick is to make changeCol be an RPC function. Then remember to never just set color=c2;. Instead, always use network.changeCol(c2, All); (I forget the exact syntax.) That tells Unity to “write a letter” (RPC) to all the other players and you, asking them to run changeCol on their copy.

I FIXED IT! All I needed to do was pass the correct material id through the RPC function. I wasn’t using any parameters before, and within the function setting the material based on a variable saved in player prefs. Feels good to finally have it working after 3 DAYS of this bug haha!

Hey I have a question if I “link up” 2 Scripts about public static in a player, can affect also other players?

For example:
I go, (public static bool walk = true)
→ then go all players on the server? Although only I press “w”?

->Of course I have not used this, but einaml was public static unvermeindlich ,I have also a qustion to this :

if i have 2 scripts on a player “connected” with a public static bool or else (all in one player), does it Change other Players bools ? Or not… ?

Sorry for my english skills XD