So it might sound dumb…
So it might sound dumb but for the last week I was mentally stuck on a problem in the Golf Demo, and that was making the Scoreboard work in a networked scenario. The issue was simple, Unity’s new Netcode system doesn’t automatically network Enumerables such as lists. I was using a List object to contain all the Player’s current data. Therefore, only the server would have the data on it, and no one else. So there’s a few different ways to address this issue. My first thought was “Well what Enumerable does work automatically networked” and the first thing that came to mind was to just let my IDE tell me by typing NetworkList, and lo and behold there was a Networked version of list, except it just didn’t work in any way, there wasn’t much documentation, and what was there didn’t really work either.
![](https://trew.tk/blog/wp-content/uploads/2022/11/leaderboard-1024x504.png)
The old proverb about forest for the trees rang true when I realized that I was maybe committed too much to trying to force things to be on the “easy” path. Typically, if I can allow a library to do the work for me, I will. And that somewhat blinded me to what I should do in this case. The worse part is that I allowed this to push me into other parts of my life, gaming, video production, classwork, home renovations, etc. all were pushed up the list. It became that thing I didn’t “want to figure out” because sometimes learning lessons in things like networking can be painful. The real pain though, was fearing the work necessary.
The solution was to make a dedicated method to sync the PlayerData with Client and Server. I made this call in two events. The first being whenever a player “hits” their ball. The second is when a player checks the score. Both are events driven by the player and only syncs from sever. The client doesn’t keep track of when other players hit their balls, and maybe they should to reduce network traffic. Regardless this was my solution, though I do admit a timed sync event to refresh scores occasionally with iterations of score being networked alongside the actual movement would probably be fine as well, and perhaps better for bandwidth reasons, and be much better then blasting out all of the information to every client whenever scores change. Though for me when developing a simple demo I don’t feel it necessary to always take the best solution, and often in production there isn’t necessarily a “Best” solution, especially when developing a game where you have to account for network lag, computer performance, and possibly cheating.
Anyhow, that’s been my week. Join me next time when I hopefully finish user configuration and might make a proper looking level for the game.