question

jkcrescenzi avatar image
jkcrescenzi asked

How to associate player data to characters

Hi, I'm very new to playfab. When organizing what data is required for my game, it falls into two main categories:

Player Inventory (a master list of items a player owns. Will likely be a collection of IDs)

Character Data (Level, Xp, current equipment loadout and ability loadout, selected customization options)

My conundrum is that there will be many characters per player. Think of characters NOT as characters (such in the case of skyrim), but rather characters are "operators" such as in Siege, Valorant, Apex Legends, Etc.

How would I write and read my data to Playfab to distinguish character data?

I know playfab has Inventory V2 and Characters... but I do not know how to use these features yet.

For reference, here is my save function.

  public void SaveData()
     {
    
         var data = new Dictionary<string, object>()
         {
             { "Health", 100 },
             { "Mana", 10000 }
         };
    
         var dataList = new List<SetObject>()
         {
             new SetObject()
             {
                 ObjectName = "PlayerData",
                 DataObject = data
             }
         };
         // A free-tier customer may store up to 3 objects on each entity
    
         PlayFabDataAPI.SetObjects(new SetObjectsRequest()
         {
             Entity = new EntityKey { Id = NetworkVariables.LoginResultData.EntityToken.Entity.Id, Type = NetworkVariables.LoginResultData.EntityToken.Entity.Type },
             Objects = dataList,
         }, (setResult) =>
         {
             Debug.Log(setResult.ProfileVersion);
         }, OnSaveLoadError);
     }
entitiesCharacter 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

·
Neils Shi avatar image
Neils Shi answered

To distinguish character data, each character is given a unique CharacterId after you call the API GrantCharacterToUser to grant the character to users. Then you can use this CharacterId to read or write data specific to that character. For example, you can call API UpdateCharacterData/GetCharacterData with the CharacterId to update or retrieve the specific character’s 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.

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.