Download

Creating Unique Server Variable Per Connected Client

I need to find a way to have my server store a unique string variable (PlayerIdentity) for every connected client. The way I have it currently set up is that upon entering credentials into a log-in screen, players are authenticated and their PlayerIdentity is stored in a string in the PlayerController blueprint. Also in the PlayerController blueprint I have a custom Run On Server event that retrieves this variable and records the player’s position vector to a database. This event / database access only runs on the server and should never be replicated or passed to clients.

This all works however the issue I am having is that when I log in and authenticate a second client, their PlayerIdentity variable seems to overwrite the first client and then the server only stores data for the most recent authentication. It seems like the server is only storing 1 PlayerIdentity variable rather than an array of PlayerIdentity variables based upon who is connected.

Any thoughts on how I might resolve this? I’m at my office at the moment so I can’t post a blueprint screenshot but I can definitely get one later tonight.

Is PlayerController the right place to be storing this unique per user variable? Should it be in GameInstance?

I just read through your post quickly. But you should have a look at the PlayState class. It has a “PlayerID” variable which is unique for each player. It is being initialized automatically when the player joins the game.
Maybe that will help.

Thanks for the reply. I’ll take a look at that later tonight but I’m not sure it will work for what I need because I need the ID variable to be persistent and connected to the login authorization. That permanent ID is used for all database entries for that character. When they log off and then log in the next day it needs that exact same ID in order to get their data. If the built in PlayerID was different every time that client connected, it wouldn’t work.