question

ilberturkyilmaz avatar image
ilberturkyilmaz asked

,Getting PlayerTitle

,

Need help on Username Login. When I wathced the tutorial eveyting was just fine. After that ı did it myself and I always get this error. I do not know where did I made the mistake.

I tried to solve this problem by deleting the first if statement but when I did that It did not ask for any username. I do think that the problem is in the 85th line. I do not know how to get the playerdisplayname.

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.

ilberturkyilmaz avatar image ilberturkyilmaz commented ·

the error shown in the second photo is not in the line of the 83rd but the 82nd

0 Likes 0 ·
Made Wang avatar image
Made Wang answered

The first thing to confirm is, is the Username or DisplayeName that needs to be obtained or modified?

If you want to make sure every new user has DisplayName or UserName, you need to add DisplayName or UserName parameter in RegisterPlayFabUserRequestBody. Refer to the code below. It is recommended to read Authentication - Register PlayFab User - REST API (PlayFab Client) | Microsoft Docs to understand the meaning of each parameter.

 var request = new RegisterPlayFabUserRequest
 {
     Email = " ",
     Password = " ",
     DisplayName = " ",
     Username = " ",
     RequireBothUsernameAndEmail = true
 };
 PlayFabClientAPI.RegisterPlayFabUser(request, OnRegisterSucces, OnError);

Like DisplayName, you can also set GetUserAccountInfo to true in the login request, and then get the username in the callback via result.InfoResultPayload.AccountInfo.Username.

5 comments
10 |1200

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

ilberturkyilmaz avatar image ilberturkyilmaz commented ·

Excuse me If I did something wrong but considering that I m new at the multiplayer part. I might be bad at coding. I tried to do what you said but it again gave the same error "NullReferenceException: Object reference not set to an instance of an object cs86"

I wish I could do better.

Here is the code that I tried to update.

https://paste.ofcode.org/WrvUNZChwWPmsSYWNwceQK

0 Likes 0 ·
ilberturkyilmaz avatar image ilberturkyilmaz commented ·

I tried to do a 2nd revision. This time it always asks for a username if its value is like null. Can you please help me?

https://paste.ofcode.org/D4R7yEmKpYmyAaJCFzYvhT

0 Likes 0 ·
ilberturkyilmaz avatar image ilberturkyilmaz commented ·

Hi again! @Made Wang . I thought of a new idea. Instead of having to use all these if parameters I Thought that I should have put namefield.setactive in the onregistersucces method. This way when the player registers he has to register his username also, if not the namepanel would not go off. by doing like this, the only downside I can think of, if player registers but does not put his username and closes the game off, he could still be able to play without a username. But ı think this will get my job done. In conclusion, what I did was instead of using if parameters to check the player has a username or not in the login parameters, I forced player to register with Username. Thanks for your hard work trying to support a new developer like me. Let me know what you think please.

0 Likes 0 ·
Made Wang avatar image Made Wang ilberturkyilmaz commented ·

First to clarify, Username and DisplayName are different, Username is used when registering and logging in, and usually only the player himself knows his Username. And DisplayName is the player's name in the game, which can be shared with other players. I still recommend that you read their descriptions in the documentation to determine which one you need.

It is possible to force the player to set the Username when registering, which is what I gave the above code for. You can ask the player to enter a Username and pass it to the RegisterPlayFabUserRequestBody, if the player input is empty or does not conform to PlayFab's specifications, the API will return an error message. You can output the error message directly to the player and tell them that the registration failed, and they must fill in the Username. On the UI you also don't need to create a separate page for Username, you can just put it on the same page as Email, Password and ask players to fill in it when registering.

1 Like 1 ·
ilberturkyilmaz avatar image ilberturkyilmaz Made Wang commented ·

I did not know that username and displayname were different. I was using the "username" as displayname. I used to need displayname and I managed to do what I wanted. Thank you for your support.

0 Likes 0 ·
Made Wang avatar image
Made Wang answered

Have you set InfoRequestParameters in the login function? You can refer to the code below. If you still encounter this problem, please provide your code so that we can reproduce.

    void Start()
    {
        PlayFabClientAPI.LoginWithEmailAddress(new LoginWithEmailAddressRequest
        {
            Email = " ",
            Password = " ",
            InfoRequestParameters = new GetPlayerCombinedInfoRequestParams
            {
                GetPlayerProfile = true,
                ProfileConstraints = new PlayerProfileViewConstraints
                {
                    ShowDisplayName = true
                }
            }
        }, LoginSuccess, LoginError);   
    }

    private void LoginSuccess(LoginResult result)
    {
        if (result.InfoResultPayload.PlayerProfile != null)
            Debug.Log(result.InfoResultPayload.PlayerProfile.DisplayName);
        else
            Debug.Log("something error");
    }

    private void LoginError(PlayFabError error)
    {
        Debug.LogError(error.GenerateErrorReport());
    }
4 comments
10 |1200

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

ilberturkyilmaz avatar image ilberturkyilmaz commented ·

my code is in the link. https://paste.ofcode.org/bdbVRt2zNyxm3naRKnyZqQ

The solution that I found temporarily is that sumitting the DiplayID everytime that player loggs in. but this causes something like player can change his username in every login and this can cause some problems. I managed to do that with the code in the 80th line by setting its value to null to open the Usernamepanel. If i try to run the code in the 81st and the 82nd line the error pops up that I uploaded the photo of.

0 Likes 0 ·
Made Wang avatar image Made Wang ilberturkyilmaz commented ·

You have two functions about login, in my testing, Login() works fine, LoginButton() returns the error you said. Which one did you use? If it is LoginButton(), you can refer to my code above and add the configuration about InfoRequestParameters after line 42.

1 Like 1 ·
ilberturkyilmaz avatar image ilberturkyilmaz Made Wang commented ·

I m not using the one in the Start() function. It was for quick tests. You can completely deny it. The one that I use is LoginButton(). I implemented the part that you gave me from the line 7th to 14th. It works. It does not show any errors but It also does not ask for a username for a newly created account. The fresh player can play the game without a username. It does not check if the player has a username. I want it to be like in every game. If player has a username it should not ask for more but if player does not have one it has to ask after registeration.

0 Likes 0 ·
Show more comments

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.