Currently, the only way of adding a friend is by adding it via the ID. But this ID can only be retrieved if the player sends it to the other person in some way, like discord.
Will there be the possibility of adding friends by using the name#number format?
Hi MiTscMR, I believe the ability to add a friend using their name#number was added to the 0.2.0-preview.9 build, it was just not documented. The docs got updated recently, I hope this helps
In case you are curious you also have the ability to have each user set their own name and not have the autogenerated one. More information here
Thanks a lot for this information, great to hear that was implemented!
About the the names, I am confused as to what is included in the profile data. If the player doesn’t have a player name set, it uses the auto generated one for the friends system and if he does have one, it uses that or what? Because from my understanding, you can’t get the player name from someone else within the authentication service.
If the player does not have a player name set, then the friends system will contact the authentication service to get an auto-generated name for said player.
If the player already set a name using the authentication service then the friends system will use the name that was set using the authentication service.
Ultimately the player name will always reside within the authentication service. Friends just requests to have one autogenerated if one was not set prior, until the player decides to change it.
@AlfredoMurillo I have one problem. Currently in my game I am implementing the sign-in by username/password combination. The problem is I can’t use the username for friend request. Let me explain:
To send the friend request I use the following code:
Here in the playerName if you use Username it will not work. Rather you have to use PlayerName which is got when the following piece of code is executed after you login in.
But when you get the PlayerName by the GetPlayerNameAsync() method it is username+“#”+number.
Also each time I update the playername and retrieve it the number keeps changing. I cant understand that if the username is unique why you have to append a random number to the end?
So my question is how do I send the friend request only by the username alone and nothing else? Is there any API call for that?
You are correct that the method AddFriendByNameAsync(playerName) is not the username that you have for username/password authentication. Rather it uses whats know as unity profile names which to guarantee that they are unique is generated with an extra number at then end.
However this shouldn’t be to much of a problem for your usecase.
Step 1: Login with username password
Step 2: Check Name retrieved by AuthenticationService.Instance.GetPlayerNameAsync();
Step3: If the TEXT part of # is not your username update the player name by calling AuthenticationService.Instance.UpdatePlayerNameAsync(userName);
Now you have a username that is associated to a player name which can be used in the FriendsService.Instance.AddFriendByNameAsync(playerName).
The IF statement will make sure that the player never updates their name other then the first time they are logged in (you could do something more elegant but the trick is to only update on the first login so the numbers dont change) .
See that is what I tried doing , but when I tried using AuthenticationService.Instance.GetPlayerNameAsync();
after using AuthenticationService.Instance.UpdatePlayerNameAsync(userName)
it is returning username+“#”+randomNumber. If I use only the username to send the friend request from the other user it is not working at all.
So my question is if the username is unique why postfix it “#”+randomNumber and keep changing it every time you retrieve it.
Also it would be good if you could use some method which to send friend request which is just based on username only
Unfortunately thats not how the profile names work.
You can see details on how player profile management works. In short the profile names doesn’t know exactly what mechanism the authentication service is using therefore to guarantee name uniqueness it needs to add the number hash.