Converting user IDs to strings and back
Serialize a user ID to a string value
- C++
- Blueprints
You can serialize a user ID to a string value by using the ToString()
function on the user ID:
// TSharedPtr<const FUniqueNetId> UserId
FString UserIdSerialized = UserId->ToString();
Deserialize a string value into a user ID
- C++
- Blueprints
You can deserialize a string value into a user ID by using the CreateUniquePlayerId
function on the identity interface:
IOnlineSubsystem *Subsystem = Online::GetSubsystem(this->GetWorld());
IOnlineIdentityPtr Identity = Subsystem->GetIdentityInterface();
// FString UserIdSerialized
TSharedPtr<const FUniqueNetId> UserId = Identity->CreateUniquePlayerId(UserIdSerialized);
if (UserId.IsValid())
{
// User ID was deserialized successfully, but this doesn't necessarily
// mean the user exists. If you need to check if the user exists,
// use the IOnlineUser interface.
}