Search Unity

Resolved Add Friends By Name?

Discussion in 'Friends' started by MiTschMR, Apr 21, 2023.

  1. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    489
    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?
     
  2. AlfredoMurillo

    AlfredoMurillo

    Unity Technologies

    Joined:
    Apr 21, 2023
    Posts:
    2
    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
     
  3. MiTschMR

    MiTschMR

    Joined:
    Aug 28, 2018
    Posts:
    489
    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.
     
  4. AlfredoMurillo

    AlfredoMurillo

    Unity Technologies

    Joined:
    Apr 21, 2023
    Posts:
    2
    Glad I could help,

    The profile name works this way:

    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.
     
    MiTschMR likes this.
  5. Chethan007

    Chethan007

    Joined:
    Dec 3, 2020
    Posts:
    57
    @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:

    Code (CSharp):
    1. await FriendsService.Instance.AddFriendByNameAsync(playerName)
    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.

    Code (CSharp):
    1. playerName = await AuthenticationService.Instance.GetPlayerNameAsync();
    But this playerName is some random name you get , which is no way connected to the username as such.

    To overcome this I updated the PlayerName with username , using the following piece of code

    Code (CSharp):
    1. string playerName = await AuthenticationService.Instance.UpdatePlayerNameAsync(userName);
    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?