question

cruella avatar image
cruella asked

Add Custom Data to Player item in client

Im trying to make runes as item. Each rune should have their "Level" and "RuneType" Datas.
I can manually add those datas in playfab.

However, I CANT add or CHANGE any values of player's specific rune's custom datas.

Whenever I chance values in playfab, Values are shows correctly in unity.

But, I cant chance in unity, which makes a problem for me.
I've tried those codes, which doesnt give an error, but does nothing.

       result.Inventory[0].CustomData["Test"] = "99";
        result.Inventory[0].CustomData.Add("Test", "99");
        result.Inventory[0].CustomData = new Dictionary<string, string> { { "Test", "555" } };
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

·
Citrus Yan avatar image
Citrus Yan answered

Item custom data is read-only from the client-side, therefore you cannot add or change their values from the client-side (there is no client API for it). Instead, you’d need to update their values using the server API UpdateUserInventoryItemCustomData from the server-side, such as CloudScript. For more details about how to write custom CloudScript, please check out this tutorial: Writing custom CloudScript - PlayFab | Microsoft Docs

2 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.

cruella avatar image cruella commented ·

Oh, good to know that.
But still one thing that bugs me, why CustomData has an "add" method, if its read only from cliend side? Im referring to ->

  result.Inventory[0].CustomData.Add("Test", "99");
0 Likes 0 ·
Citrus Yan avatar image Citrus Yan cruella commented ·

"CustomData" is defined as a Dictionary<string, string> in PlayFab Unity SDK :

        public Dictionary<string,string> CustomData;

Therefore the "Add" method comes from the Dictionary: Dictionary<TKey,TValue>.Add(TKey, TValue) Method (System.Collections.Generic) | Microsoft Docs, which has nothing to do with PlayFab though.

0 Likes 0 ·

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.