question

deaverinc avatar image
deaverinc asked

write display name back to playfab

i have a wierd situation that i need help with. i created an account with user name, password and email and also tried to assign the display name when the playfab account was created. it usually works but one time i did get an account created that did not assign the display name. the playfab username is populated but the display name field is not. since i am using player prefs to store the information on each device i do have the playfab name created on register and can use it in the game but how can i write that information back to playfab in case there is another situation where this happens? to slightly complicate my question i am also using PlayFabAuthenticator(); from the tutorial which works fine but it does create a second player id which is linked to the original player id. i need to be able to write the display name to both for clarity as the number of accounts created grows. i am using c# and would appreciate any help. here is my code for trying to initially populate the display name field. thanks.

***THIS IS IN THE PLAYFABCODE SCRIPT USED TO CREATE AN ACCOUNT ***

public InputField Username, Email, Password;

public Text ErrorMessage;

private string userName, userEmail, userPassword;

public void RegisterClick()

{

var register = new RegisterPlayFabUserRequest

{

Username = Username.text,

Email = Email.text,

Password = Password.text,

DisplayName = userName

};

PlayFabClientAPI.RegisterPlayFabUser(register, OnRegisterSuccess, OnRegisterFailure);

}

private void OnRegisterSuccess(RegisterPlayFabUserResult result)

{

ErrorMessage.text = "";

userEmail = Email.text;

userName = Username.text;

userPassword = Password.text;

PlayerPrefs.SetString("EMAIL", userEmail);

PlayerPrefs.SetString("PASSWORD", userPassword);

PlayerPrefs.SetString("USERNAME", userName);

AccountInfo.StartAccountInfo(result.PlayFabId);

SceneManager.LoadScene(sceneName: "InitialSetup");

}

PlayFabAuthenticator() is launched on awake from the AccountInfo script and follows the tutorial

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

deaverinc avatar image deaverinc commented ·

i have read up on entity id and type but i am not sure if this is the way to go. if so i could use a detailed tut since i am not getting the example to work. thanks.

0 Likes 0 ·
Made Wang avatar image
Made Wang answered

You can call UpdateUserTitleDisplayName to update the display name.

I noticed that you assign userName to DisplayName, but userName is null in the initial condition, is this the reason the first write is null? Also, we don't recommend setting UserName to the same thing as DisplayName, UserName used for authentication should not be known to other users.

You mentioned in your new reply that you call RegisterPlayFabUser to register the account and LoginWithCustomID to log in to the account. It should be noted that RegisterPlayFabUser does not link accounts with custom Id, you need to call LinkCustomID to link them, and then call LoginWithCustomID, so that you can log in to the same account. For getting entity information, you can refer to the following code.

    public void LoginWithCustomID()
    {
        PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest
        {
            CustomId = ""
        },
        (result) =>
        {
            entityId = result.EntityToken.Entity.Id;
            entityType = result.EntityToken.Entity.Type;
        },
        (error) =>
        {
            Debug.LogError(error.GenerateErrorReport());
        });
    }

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

deaverinc avatar image
deaverinc answered

ok, so i feel like i am close but at a lose as to how to resolve. i am initially registering the account with RegisterPlayFabUser and authenticating using LoginWithCustomID. i am using this code to try to write back to playfab what the display name should be:

public static void AddDisplayName()

{

var data = new Dictionary<string, string>()

{

{playFabId, PlayerPrefs.GetString("USERNAME")},

{_playFabPlayerIdCache, PlayerPrefs.GetString("USERNAME") }

};

var dataList = new List<SetObject>()

{ new SetObject()

{ObjectName = "DisplayName",

DataObject = data },

};

PlayFabDataAPI.SetObjects(new SetObjectsRequest()

{ Entity = new PlayFab.DataModels.EntityKey { Id = entityId, Type = entityType },

Objects = dataList, },

(setResult) => { Debug.Log(setResult.ProfileVersion); },

OnPlayFabError);

var getRequest = new GetObjectsRequest

{ Entity = new PlayFab.DataModels.EntityKey { Id = entityId, Type = entityType } }; PlayFabDataAPI.GetObjects(getRequest, result => { var objs = result.Objects; }, GameFunctions.PlayFabAPIFailure );

If i understand correctly i can get the entity id and entity type from the LoginWithCustomID but i cant find any specific code tor an example. can someone please show me?

private void AuthenticateWithPlayFab()

{ LogMessage("PlayFab authenticating using Custom ID...");

PlayFabClientAPI.LoginWithCustomID(new LoginWithCustomIDRequest()

{ CreateAccount = true,

CustomId = PlayFabSettings.DeviceUniqueIdentifier },

RequestPhotonToken, OnPlayFabError); }

10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.