question

nathancarpenter avatar image
nathancarpenter asked

Having trouble with saving player data,Having trouble saving player data

When using the following code it returns the error:

"/Object/SetObjects: Invalid input parameters Objects: The field Objects must be a string or array type with a minimum length of '1'."

I am new to PlayFab so I am not sure if I am just missing something here. Looking at the example here it looks to be correct:

https://learn.microsoft.com/en-us/gaming/playfab/features/data/entities/entity-objects

Debugging the 'data' dictionary I confirmed it does have the two entries. However when debugging the 'dataList' it contains zero entries after creating the new SetObject. Is someone able to point me in the right direction as to what I am doing wrong please?

 public void SavePlayerData()
    {


        var data = new Dictionary<string, object>()
        {
            {"Cash", GameManager.instance.cash },
            {"Rubies", GameManager.instance.rubies }
            
        };


        Debug.Log(data.Count);


        var dataList = new List<SetObject>();
        {
            new SetObject()
            {
                ObjectName = "PlayerData",
                DataObject = data
            };
        };


        Debug.Log(dataList.Count);


        PlayFabDataAPI.SetObjects(new SetObjectsRequest()
        {
            Entity = new EntityKey { Id = entityKey.Entity.Id, Type = entityKey.Entity.Type },
            Objects = dataList, 
            
        }, (setResult) => 
        {
            Debug.Log(setResult.ProfileVersion);
        },  OnPlayFabError);
    }
,
When using the following code it returns the error: 
"/Object/SetObjects: Invalid input parameters
Objects: The field Objects must be a string or array type with a minimum length of '1'."

I am new to PlayFab so I am not sure if I am just missing something here. Looking at the example here it looks to be correct:
https://learn.microsoft.com/en-us/gaming/playfab/features/data/entities/entity-objects

Debugging the 'data' dictionary I confirmed it does have the two entries. However when  debugging the 'dataList' it contains zero entries after creating the new SetObject.

Is someone able to point me in the right direction as to what I am doing wrong please?



public void SavePlayerData() { var data = new Dictionary<string, object>() { {"Cash", GameManager.instance.cash }, {"Rubies", GameManager.instance.rubies } }; Debug.Log(data.Count); var dataList = new List<SetObject>(); { new SetObject() { ObjectName = "PlayerData", DataObject = data }; }; Debug.Log(dataList.Count); PlayFabDataAPI.SetObjects(new SetObjectsRequest() { Entity = new EntityKey { Id = entityKey.Entity.Id, Type = entityKey.Entity.Type }, Objects = dataList, }, (setResult) => { Debug.Log(setResult.ProfileVersion); }, OnPlayFabError); }
Player Dataentities
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

·
nathancarpenter avatar image
nathancarpenter answered

Seems I was looking into this way to hard and realized that I was never adding the new SetObject to my list and this was why it was returning empty.

Added the new SetObject to my list and now everything is working.

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.