> ## Documentation Index
> Fetch the complete documentation index at: https://devdocs.xbox.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 読み取り専用プレイヤーデータの設定方法

> Server API から読み取り専用の PlayFab プレイヤーデータを書き込み、クライアントが権威ある進行値を変更できずに読み取れるようにします。

読み取り専用の KVP を設定するには、サーバープロセスから Server API の [UpdateUserReadOnlyData](xref:titleid.playfabapi.com.server.playerdatamanagement.updateuserreadonlydata) メソッドを呼び出す必要があります。これはサーバーが変更できるが、クライアントは読み取りのみ可能なデータです。

このトピックの C# サンプルは Unity SDK 用に書かれています。Unity SDK は、非同期タスクを処理するためにイベントドリブンモデルを使用します。C# SDK を使用してサンプルコードを実行するには、非同期タスクモデルを使用するようにコードを変更する必要があります。変更が必要なメソッドは、シグネチャ内のメソッド名に Async が追加されています。たとえば、Unity SDK の SetObject は C# SDK では SetObjectAsync になります。詳細については、[Asynchronous programming with async and await](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/concepts/async/) を参照してください。

## C# コード例

次の **C#** コード例では、PlayFab Server API を使用して、`Father` という名前のキーに値 `Fred`、`Mother` に値 `Alice`、`Sister` に値 `Lucy`、`Brother` に値 `Doug` を設定して KVP を作成 (または KVP がすでに存在する場合は更新) します。

```csharp theme={null}
public void UpdateUserReadOnlyData() {
    PlayFabServerAPI.UpdateUserReadOnlyData(new UpdateUserDataRequest() {
        PlayFabId = "user PlayFabId here - obtained from any successful LoginResult",
        Data = new Dictionary<string, string>() {
            {"Father", "Fred"},
            {"Mother", "Alice"},
            {"Sister", "Lucy"},
            {"Brother", "Doug"}
        },
        Permission = UserDataPermission.Public
    },
    result => Debug.Log("Set read-only user data successful"),
    error => {
        Debug.Log("Got error updating read-only user data:");
        Debug.Log(error.GenerateErrorReport());
    });
}
```

## 関連項目

[読み取り専用プレイヤーデータの取得方法](/services/playfab/player-progression/player-data/how-to-get-read-only-player-data)


## Related topics

- [読み取り専用プレイヤーデータの取得方法](/ja-jp/services/playfab/player-progression/player-data/how-to-get-read-only-player-data.md)
- [プレイヤーデータのクイックスタート](/ja-jp/services/playfab/player-progression/player-data/quickstart.md)
- [CloudScript を介した読み取り専用または内部プレイヤーデータの変更](/ja-jp/services/playfab/player-progression/player-data/how-to-modify-read-only-internal-player-data.md)
- [内部プレイヤーデータの設定方法](/ja-jp/services/playfab/player-progression/player-data/how-to-set-internal-player-data.md)
- [内部プレイヤーデータの取得方法](/ja-jp/services/playfab/player-progression/player-data/how-to-get-internal-player-data.md)
