I am having this problem but I struggle to find a way to properly address it.
I have a string type "username" field of the player instance that I want to send from the server to the client. Let's say there are 300 players in the game. I don't want to send the "username" too often because that will stack up the data package size both sent out from the server and received by the client. Sadly I am doing this right now and it is costly.
All I want is to show the player's username on the screen of the client. It will always be on top of each player's entity. If the players are always on the client that is very easy to code. I will just send all usernames once and assign them to all the players. Done.
Tricky thing is, the players are often on and off the screen when they move, which means another player will move inside of a player's view or outside of his view. So every time the client receives the data package from the server, it will try to look for the players that matches the existing usernames, if the "username" field was not sent in every update package. This will require me to maintain a data structure that frequently adds and removes a "username" value and search for one that matches the package and the client side and then display it. I may need to match the players and the existing names on the client side by using their IDs.
This may seem obvious. But before I implement anything. I just want to know if there is any standard/common way to do this in game?