question

zacklangan avatar image
zacklangan asked

Create character Object reference not set to an instance of an object

I get the error "Object reference not set to an instance of an object."

   public void CreateCharacter()
    {
        GrantCharacterToUserRequest request = new GrantCharacterToUserRequest();
        request.CatalogVersion = "Consumables";
        request.ItemId = "Character Creation Token";
        request.CharacterName = name.text;
        PlayFabClientAPI.GrantCharacterToUser(request, result => 
        {
            Debug.Log("Succesfully created character ");
            Debug.Log("1 " + result.CharacterId);
            Debug.Log("2 " + result.CharacterType);
            Debug.Log("3 " + result.CustomData);
            Debug.Log("4 " + result.Request);
            Debug.Log("5 " + result.Result);


        }, error => 
        {
            Debug.Log(error.ErrorMessage);
        });
    }
Character Data
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

·
JayZuo avatar image
JayZuo answered

Your code looks right. The only possible cause of your error is "name.text". It seems you want to get character name form UGUI. Please make sure you have already set name to a UI object in Inspector.

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.