Hi everybody,
maybe this is a very stupid question, but I’m struggling with this for 2 days now.
My problem seems to be simple:
I have a c# class with player data in it (think of score, ammo, player name and so on). Let’s call it PlayerData for now. And there is a List.
When starting a network game, my server is creating a first entry to this list for it’s local player. No problem so far. ![]()
Now I want to do the following:
-
Add an entry to my playerlist every time a new client connects to server.
-
Sync values of PlayerData when client or server has changed something (I maintain a Changed-Flag for this purpose). After connecting a client has to set it’s username, later server may change scores for example.
-
Finally, remove PlayerData from list when a client disconnets from server.
I did the trick moving serialized PlayerData using RPCs from client to server and vice versa. But I’m not sure, if there isn’t a better way of doing this?
I encountered another problem when a client is disconnecting: I hold corresponding NetworkPlayer in every PlayerData, so I thought it would be an easy task to remove old PlayerData from list - just looping through list and removing every entry for disconnected NetworkPlayer. But it doesn’t work for some reason.
Well, basically I would be happy with some kind of unique NetworkPlayer-ID, that enables me to link my PlayerData objects to a specific NetworkPlayer without need of storing whole NetworkPlayer (or it’s reference, what may cause my above problems).
I read in some forum posts, that player.ToString() (talking of NetworkPlayer, of course) should gimme some global ID. But when checking out, Debug.Log(player.ToString()); prints “0” for client and server every time I connect (via LAN).
How did you do networked playerlists in your projects?
Btw, is there a reason, why Unity’s MasterServer is ignoring my limitation to max 4 connections (in Network.InitializeServer and Network.maxConnections)? Hostlist keeps saying that my game would accept up to 5 connections. Interesting, should be one less. ![]()
Thank you all in advance! ![]()
Christian