question

Bernhard Hofer avatar image
Bernhard Hofer asked

GrantCharacterToUser

    public void AddCharacterToUser(InputField characterName)
    {
        var request = new GrantCharacterToUserRequest();
        request.CharacterName = characterName.text;

        PlayFabClientAPI.GrantCharacterToUser(request, OnSucess, OnFailure);
    }


Hey I need help! I'm pretty new at PlayFab. I have a working Login System all is working fine. I create a RPG game where I can add Multiple Characters .. I want add the Characters to my PlayFabAccount and created this function. But I always get as error message!


Invalid input parameters

    private void OnFailure(PlayFabError obj)
    {
        Debug.Log(obj.ErrorMessage);
    }

    private void OnSucess(GrantCharacterToUserResult obj)
    {
        Debug.Log("Hat funktioniert");
    }

What Im doing wrong ?

Thanks for HELP!
10 |1200

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

1 Answer

·
Sarah Zhang avatar image
Sarah Zhang answered

Firstly, for troubleshooting, you can check the API reference of Client API GrantCharacterToUser. As the API reference shows, your request body lacks the required field – ItemId. So this API call returns the “Invalid input parameters” error. In the client code, you can add the Debug.Log(obj.GenerateErrorReport()); to print the error details in the console.

Besides, you may need to learn about the differences between Client API GrantCharacterToUser and Server API GrantCharacterToUser. The following thread gives a detailed explanation of them.

Character creation - Server/Client differences

As a summary, you can use Server API GrantCharacterToUser on PlayFab CloudScript or custom severs to grant the character to the specific player directly. But you need to grant an item which is a token for character creation to the player before you use Client API GrantCharacterToUser for him. To create an item that is a character creation token, you can check the [Is a token for character creation] option in the [Edit Item] page.

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.