I’ve been having a hard time trying to update a variable in Player State.
So what I’m trying to do is to store device ID from each player in player state, using that to make a call to our backend. Essentially it servers as a user ID kind of thing for us.
The problem was that PlayerState was storing DeviceID of the Server, not client’s machine. Here is what I tried so far:
I added two RPCs in our extension of player state
---- .h
UFUNCTION(Reliable, Client)
void SetClientID();
void SetClientID_Implementation();
UFUNCTION(Reliable, Server, WithValidation)
void SetClientIDCallBack(const FString& id);
void SetClientIDCallBack_Implementation(const FString& id);
bool SetClientIDCallBack_Validate(const FString& id);
--- .cpp
void ...::SetClientID_Implementation()
{
SetClientIDCallBack(..Misc::GetDeviceID());
}
void ...::SetClientIDCallBack_Implementation(const FString& id)
{
DeviceID = id;
}
and I call this function inside out GameState for each PlayerState.
I put UE_LOG statement in the call back function and client is indeed passing its deviceID correctly,
but PlayerState owned by server never gets updated.
I’ve also tried to put this function in Player Controller, and call it from there. Still doesn’t work.
At this point I’m stuck and don’t know what to do. How do I update the variable of Player State? All of this is happening in c++ by the way.