Implementing Nickname Change
1. Write the nickname change method
Add content to the ChangeDisplayName method in BackndLogin.cs written in Pre-arrangements.
BackndLogin.cs
Before editing
public void ChangeDisplayName(string nickname) {
// Logic for Step 4. Implementing Nickname Change
}
After editing
public void ChangeDisplayName(string nickname) {
Debug.Log("Requesting nickname change.");
var bro = Backnd.Player.ChangeDisplayName(nickname);
if(bro.IsSuccess()) {
Debug.Log("Nickname change successful : " + bro);
} else {
Debug.LogError("Nickname change failed : " + bro);
}
}
2. Add method call to BackndManager.cs
BackndManager, which is automatically called when the game is executed, must be used to call this method.
Add it so that the method may be called after BACKND initialization.
BackndManager.cs Before editing
async void Test() {
await Task.Run(() => {
BackndLogin.Instance.CustomSignIn("user1","1234"); // [Addition] BACKND login
Debug.Log("Test complete.");
});
}
After editing
async void Test() {
await Task.Run(() => {
BackndLogin.Instance.CustomSignIn("user1","1234"); // [Addition] BACKND login
BackndLogin.Instance.ChangeDisplayName("Desired nickname"); // [Addition] Change nickname
Debug.Log("Test complete.");
});
}
3. Test in Unity
After editing the script, execute Unity debugging and check the console log of Unity.
The method has been successfully called when the log displays 'Nickname change successful. : statusCode : 204'.
When errors, such as statusCode : 400, 404, and 409, occur instead of the above log, you can check which error caused the failure in ChangeDisplayName error case.
When statusCode : 409 error occurs
When changing the nickname 2 or more times without changing the logic, this error occurs due to the command attempting to change the nickname to a preexisting one.
The parameter value that goes inside ChangeDisplayName of BackndManager.cs should be changed to a value different from the nickname that was originally entered.
4. Check in the console
Go to BACKND Console, and in BACKND Base > User Management
check that the changed nickname is displayed properly for the logged-in user.