ゲームクライアントを使用してプレイヤーインベントリを管理する
注釈:本資料はAI技術を用いて翻訳されています。
インベントリサービスはリクエストに応じて利用可能です。このサービスを環境に統合するには、AccelByte カスタマーサポートポータルからリクエストを開いてください。
はじめに
AccelByte Gaming Service (AGS) インベントリサービスをゲームクライアントに統合することで、プレイヤーが自分のインベントリとアイテムを柔軟に管理できるようになります。インベントリサービスにより、プレイヤーは、保持するものと破棄するものを決定することから、ニーズや好みに応じてアイテムを整理および転送することまで、ゲーム内でさまざまな側面でアイテムを制御できます。
この記事では、プレイヤーがインベントリとアイテムを管理できるようにゲームクライアントを設定する方法について説明します。
前提条件
- AGS 管理者ポータルへのアクセス。
- パブリッシャーまたはゲームネームスペース。
- インベントリサービスの主要な概念とインベントリサービス API ドキュメントを確認していること。
- AccelByte Unreal または Unity SDK をゲームに統合していること。次の権限を含む:
- Client ID
- Client Secret
プレイヤーがインベントリ設定を取得できるようにする
インベントリ設定は、ゲームがサポートするインベントリのタイプを決定するために管理者が設定する情報とルールのセットです。設定は次のもので構成されます。
- code: インベントリ設定の ID。
- name: インベントリ設定の名前。
- description: (オプション)インベントリ設定を説明する簡単な説明または追加情報。
- maxInstancesPerUser: プレイヤーが所有できる最大インベントリ数。
- initialMaxSlots: プレイヤーがアイテムを保存できる最大スロット数。各スロットには、スタック不可能な単一のアイテム、または1つにスタックされた複数の同一アイテムを保存できます。
- maxUpgradeSlots: プレイヤーがインベントリで所有できる最大スロットアップグレード数。
インベントリ設定のリストを使用して、プレイヤーが取得できるゲーム内で利用可能なインベントリを表示できます。

プレイヤーがインベントリ設定を取得できるようにするには、この関数を使用します。
- Unreal
- Unity Engine
EAccelByteInventoryConfigurationSortBy SortBy = EAccelByteInventoryConfigurationSortBy::CREATED_AT_DESC;
FString ConfigurationCode = FString("SomeConfigurationCode");
FAccelByteModelsInventoryConfigurationsPagingResponse OutResult;
const FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
ApiClient->Inventory.GetInventoryConfigurations(
THandler<FAccelByteModelsInventoryConfigurationsPagingResponse>::CreateLambda([&](const FAccelByteModelsInventoryConfigurationsPagingResponse& Result)
{
OutResult = Result;
// Do something if GetInventoryConfigurations is successful
})
, FErrorHandler::CreateLambda([&](const int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetInventoryConfigurations has an error
}) , SortBy, 50, 0, ConfigurationCode);
Result<InventoryConfigurationsPagingResponse> getInventoryConfigResult = null;
AccelByteSDK.GetClientRegistry().GetApi().GetInventory().GetInventoryConfigurations(result =>
{
if (result.IsError)
{
Debug.Log($"Failed to get inventory config [{result.Error.Code}]:{result.Error.Message}");
return;
}
// Do something after GetInventoryConfigurations is successful
getInventoryConfigResult = result;
});
プレイヤーが自分のインベントリのリストを取得できるようにする
プレイヤーが自分のインベントリのリストを取得できるようにすることで、次の情報が提供されます。
- inventoryConfigurationCode: 特定のインベントリ設定を参照するために使用されます。
- inventoryConfigurationId: インベントリの識別子として使用されます。
- maxSlots: プレイヤーがインベントリで使用できる最大スロット数を指します。
- maxUpgradeSlots: プレイヤーがインベントリでアップグレードできる最大スロット数を指します。
- usedCountSlots: プレイヤーがすでに使用しているスロット数を指します。
inventoryConfigurationId は、さまざまなインベントリ管理機能で使用されます。
上記の情報を使用して、プレイヤーに表示できます。例:

プレイヤーが自分のインベントリのリストを取得できるようにするには、この関数を使用します。
- Unreal
- Unity Engine
EAccelByteUserInventoriesSortBy SortBy = EAccelByteUserInventoriesSortBy::CREATED_AT_DESC;
FString ConfigurationCode = FString("SomeConfigurationCode");
FAccelByteModelsUserInventoriesPagingResponse OutResult;
const FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
ApiClient->Inventory.GetUserInventories(
THandler<FAccelByteModelsUserInventoriesPagingResponse>::CreateLambda([&](const FAccelByteModelsUserInventoriesPagingResponse& Result)
{
OutResult = Result;
// Do something if GetUserInventories is successful
})
, FErrorHandler::CreateLambda([&](const int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserInventories has an error
}) , SortBy, 50, 0, ConfigurationCode);
Result<UserInventoriesPagingResponse> getInventoryResult = null;
AccelByteSDK.GetClientRegistry().GetApi().GetInventory().GetUserInventories(result =>
{
if (result.IsError)
{
Debug.Log($"Failed to get user inventory [{result.Error.Code}]:{result.Error.Message}");
return;
}
// Do something after GetUserInventories is successful
getInventoryResult = result;
});
プレイヤーがインベントリからアイテムのリストを取得できるようにする
プレイヤーが特定のインベントリ内のアイテムを確認し、次の情報を表示できるようにすることができます。
- qty: スロットにスタックできる同じアイテムの数。
- sourceItemId: アイテム辞書を検索するために使用される ID。
- slotUsed: アイテムに使用されているスロット数。
- slotId: アイテムが保存されているスロットの ID。指定されていない場合、デフォルトのスロットが default として入力されます。
- serverCustomAttributes: サーバー権限アクションのみをサポートする追加属性。
- customAttributes: プレイヤーとサーバーの両方の権限アクションをサポートする追加属性。
- type: ゲーム内アイテム、バンドル、ルートボックス、オプションボックスなどのアイテムタイプを指します。
- tag: アイテムのグループ化と分類に使用できます。
sourceItemId は、アイテム辞書を検索するために使用されます。AccelByte ストアを使用している場合、sourceItemId をストアの itemId と同じ値で入力できます。
次の画像は、サンプル実装を示しています。
-
シンプルな実装

-
qty、slotUsed、slotId を使用してアイテムを柔軟に保存する実装

-
slotUsed フィールドを特定の数値に設定することで、単一のアイテムを複数のスロットに保存できます。例えば、slotUsed: 3 は、1つの剣を3つのスロットに保存します。
-
qty フィールドを特定の数値に設定することで、複数のアイテムを単一のスロットにスタックできます。例えば、qty: 99 は、99個のポーションを単一のスロットに保存します。
-
slotId を使用して、アイテムを保存するスロットを指定できます。デフォルトでは、スロットを指定しない場合、default で入力されます。
- 2番目の実装例のように、プレイヤーがポーションを最初のスロットに保存できるようにする場合は、slotId を slotId: "0" に設定します。
- 同じポーションを別のスロットに保存する場合(例えば、2番目の実装例のように、スロットの最初の列の中央行に保存されたポーション)、slotId を slotId: "5" に設定します。
-
serverCustomAttributes と customAttributes を使用して、アイテムの寸法とスロット位置を強化できます。2番目の実装例では、剣は列5の3つのスロットを占有します。
"serverCustomAttributes": {
"slotDimensionHeight": 3,
"slotDimensionWidth":1,
},
"customAttributes": {
"slotPosition": "[0,4],[1,4],[2,4]"
}アイテムの寸法は、プレイヤーが情報を調整できないように serverCustomAttributes に保存されます。この情報は、ゲームクライアントがアイテムの寸法を識別するために使用されます。スロット位置については、customAttributes に保存して、プレイヤーがアイテムの位置を移動できるようにすることができます。
-
プレイヤーがインベントリからアイテムのリストを取得できるようにするには、この関数を使用します。
- Unreal
- Unity Engine
FString InventoryId = FString("SomeInventoryId");
EAccelByteUserItemsSortBy SortBy = EAccelByteUserItemsSortBy::CREATED_AT_DESC;
FString SourceItemId = FString("SomeSourceItemId");
FString Tags = FString("SomeTags");
FAccelByteModelsUserItemsPagingResponse OutResult;
const FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
ApiClient->Inventory.GetUserInventoryAllItems(InventoryId,
THandler<FAccelByteModelsUserItemsPagingResponse>::CreateLambda([&](const FAccelByteModelsUserItemsPagingResponse& Result)
{
OutResult = Result;
// Do something if GetUserInventoryAllItems is successful
})
, FErrorHandler::CreateLambda([&](const int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetUserInventoryAllItems has an error
}), SortBy, 50, 0, SourceItemId, Tags);
// prepare inventoryId value
// you can get this value from GetUserInventories step result as follows:
// string inventoryId = getUserInventoriesResult.value.data[0].id;
string inventoryId = "uniqueInventoryId";
Result<UserItemsPagingResponse> getItemResult = null;
AccelByteSDK.GetClientRegistry().GetApi().GetInventory().GetUserInventoryAllItems(inventoryId, result =>
{
if (result.IsError)
{
Debug.Log($"Failed to get inventory [{result.Error.Code}]:{result.Error.Message}");
return;
}
// Do something after GetUserInventoryAllItems is successful
getItemResult = result;
});
プレイヤーがアイテムの属性とタグを更新できるようにする
プレイヤーがインベントリ内のアイテムの追加情報とタグを保存できるようにすることができます。
カスタム属性
これらの属性は、プレイヤー(ゲームクライアント経由)またはゲームサーバーによって更新できます。これは、プレイヤーがアイテムに関連する追加情報を保存できるようにしたい場合に適しています。保存される属性は通常、ゲームプレイメカニクスに影響を与えないもの、例えばアイテムのスタイルやコスメティックです。この属性は customAttributes フィールドに保存されます。

タグ
プレイヤーがタグ付けとグループ化の目的でアイテムにタグを追加できるようにすることができます。
- すべてのタグがプレイヤーによって使用できるわけではありません。一部のタグは、ゲームサーバー経由でのみ追加できます。ゲームサーバー経由でタグを更新するを参照してください。
- タグは事前定義されており、管理者のみが事前定義されたタグを追加および変更できます。

この関数を使用します。
- Unreal
- Unity Engine
FJsonObjectWrapper UpdatedCustomAttributes;
UpdatedCustomAttributes.JsonObject = MakeShared<FJsonObject>();
UpdatedCustomAttributes.JsonObject->SetStringField("SomeAttributeStringKey", "UpdatedAttribute");
FAccelByteModelsUpdateUserInventoryItemRequest UpdateInventoryItemRequest = {};
UpdateInventoryItemRequest.CustomAttributes = UpdatedCustomAttributes;
UpdateInventoryItemRequest.SlotId = FString("SomeUpdatedSlotId");
UpdateInventoryItemRequest.SourceItemId = FString("SomeUpdatedSourceItemId");
UpdateInventoryItemRequest.Tags.Add(FString("SomeUpdatedTags"));
FString InventoryId = FString("SomeInventoryId");
TArray<FAccelByteModelsUpdateUserInventoryItemResponse> OutResult;
const FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
ApiClient->Inventory.BulkUpdateInventoryItems(InventoryId, { UpdateInventoryItemRequest },
THandler<TArray<FAccelByteModelsUpdateUserInventoryItemResponse>>::CreateLambda([&](const TArray<FAccelByteModelsUpdateUserInventoryItemResponse>& Result)
{
OutResult = Result;
// Do something if BulkUpdateInventoryItems is successful
})
, FErrorHandler::CreateLambda([&](const int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if BulkUpdateInventoryItems has an error
}));
Dictionary<string, object> customAttribute = new Dictionary<string, object>()
{
{"someString", "abcd"}
, {"someInt", 1234}
, {"someFloat", 10.4f}
};
// you can get this value from GetUserInventories step result as follows:
// string inventoryId = getUserInventoriesResult.value.data[0].id;
string inventoryId = "SomeInventoryId";
string[] tags = new string[]
{
"tag 1"
, "tag 2"
};
BulkUpdateInventoryItemsPayload[] payload = new BulkUpdateInventoryItemsPayload[]
{
new BulkUpdateInventoryItemsPayload(sourceItemId)
{
CustomAttributes = customAttribute,
Tags = tags
}
};
Result<UpdateUserInventoryItemResponse[]> updateResult = null;
AccelByteSDK.GetClientRegistry().GetApi().GetInventory().BulkUpdateInventoryItems(inventoryId, payload, result =>
{
if (result.IsError)
{
// Do something if BulkUpdateInventoryItems is failed
UnityEngine.Debug.Log($"Failed to update [{result.Error.Code}]:{result.Error.Message}");
return;
}
// Do something if BulkUpdateInventoryItems is successful
updateResult = result;
});
プレイヤーが利用可能なすべてのタグを取得できるようにする
プレイヤーがインベントリ内のアイテムにタグを付けるために使用できる利用可能なタグのリストを取得できるようにするには、この関数を使用します。
- Unreal
- Unity Engine
EAccelByteInventoryUtilitiesSortBy SortBy = EAccelByteInventoryUtilitiesSortBy::CREATED_AT_DESC;
FAccelByteModelsInventoryTagPagingResponse OutResult;
const FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
ApiClient->Inventory.GetInventoryTags(
THandler<FAccelByteModelsInventoryTagPagingResponse>::CreateLambda([&](const FAccelByteModelsInventoryTagPagingResponse& Result)
{
OutResult = Result;
// Do something if GetInventoryTags is successful
})
, FErrorHandler::CreateLambda([&](const int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if GetInventoryTags has an error
}), SortBy, 50, 0);
Result<InventoryTagsPagingResponse> getTagResult = null;
AccelByteSDK.GetClientRegistry().GetApi().GetInventory().GetInventoryTags(result =>
{
if (result.IsError)
{
// Do something if GetInventoryTags has an error
Debug.Log($"Failed to get inventory tags [{result.Error.Code}]:{result.Error.Message}");
return;
}
// Do something after GetInventoryTags is successful
getTagResult = result;
});
プレイヤーがアイテムを消費できるようにする
プレイヤーがインベントリ内のアイテムを消費できるようにするには、この関数を使用します。
- Unreal
- Unity Engine
FAccelByteModelsConsumeUserItemsRequest ConsumeItemsRequest = {};
ConsumeItemsRequest.SourceItemId = FString("SomeSourceItemId");
ConsumeItemsRequest.SlotId = FString("SomeSlotId");
ConsumeItemsRequest.Qty = 1;
FString InventoryId = FString("SomeInventoryId");
FAccelByteModelsUserItemResponse OutResult;
const FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
ApiClient->Inventory.ConsumeUserInventoryItem(InventoryId, { ConsumeItemsRequest },
THandler<FAccelByteModelsUserItemResponse>::CreateLambda([&](const FAccelByteModelsUserItemResponse& Result)
{
OutResult = Result;
// Do something if ConsumeUserInventoryItem is successful
})
, FErrorHandler::CreateLambda([&](const int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if ConsumeUserInventoryItem has an error
}));
// you can get this value from GetUserInventories step result as follows:
// string inventoryId = getUserInventoriesResult.value.data[0].id;
string inventoryId = "SomeInventoryId";
int expectedQuantity = 1;
// you can get this value from GetUserInventoryAllItems step result as follows:
// string sourceItemId = getUserInventoryAllItems.Value.Data[0].SourceItemId;
string sourceItemId = "someSourceItemId";
Result<UserItem> consumeResult = null;
AccelByteSDK.GetClientRegistry().GetApi().GetInventory().ConsumeUserInventoryItem(inventoryId, expectedQuantity, sourceItemId, result =>
{
if (result.IsError)
{
// Do something if ConsumeUserInventoryItem has an error
UnityEngine.Debug.Log($"Failed to consume [{result.Error.Code}]:{result.Error.Message}");
return;
}
// Do something if ConsumeUserInventoryItem is successful
consumeResult = result;
});
プレイヤーがアイテムを削除できるようにする
プレイヤーがインベントリからアイテムを削除できるようにするには、この関数を使用します。
- Unreal
- Unity Engine
FAccelByteModelsDeleteUserInventoryItemsRequest DeleteItemsRequest = {};
DeleteItemsRequest.SourceItemId = FString("SomeSourceItemId");
DeleteItemsRequest.SlotId = FString("SomeSlotId");
FString InventoryId = FString("SomeInventoryId");
TArray<FAccelByteModelsDeleteUserInventoryItemResponse> OutResult;
const FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
ApiClient->Inventory.BulkDeleteInventoryItems(InventoryId, { DeleteItemsRequest },
THandler<TArray<FAccelByteModelsDeleteUserInventoryItemResponse>>::CreateLambda([&](const TArray<FAccelByteModelsDeleteUserInventoryItemResponse>& Result)
{
OutResult = Result;
// Do something if BulkDeleteInventoryItems is successful
})
, FErrorHandler::CreateLambda([&](const int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if BulkDeleteInventoryItems has an error
}));
// you can get this value from GetUserInventories step result as follows:
// string inventoryId = getUserInventoriesResult.value.data[0].id;
string inventoryId = "SomeInventoryId";
// you can get this value from GetUserInventoryAllItems step result as follows:
// string sourceItemId = getUserInventoryAllItems.Value.Data[0].SourceItemId;
string sourceItemId = "someSourceItemId";
var payload = new BulkDeleteUserInventoryItemsPayload[]
{
new BulkDeleteUserInventoryItemsPayload(sourceItemId);
};
Result<DeleteUserInventoryItemResponse[]> deleteResult = null;
AccelByteSDK.GetClientRegistry().GetApi().GetInventory().BulkDeleteInventoryItems(inventoryId, payload, result =>
{
if (result.IsError)
{
// Do something if BulkDeleteInventoryItems has an error
UnityEngine.Debug.Log($"Failed to delete [{result.Error.Code}]:{result.Error.Message}");
return;
}
// Do something if BulkDeleteInventoryItems is successful
deleteResult = result;
});
プレイヤーがインベントリ間でアイテムを移動できるようにする
プレイヤーがインベントリ間でアイテムを移動できるようにします。これにより、プレイヤーは好みに応じてアイテムを柔軟に管理でき、ゲームプレイと戦略的な意思決定の体験が向上します。

この関数を使用します。
- Unreal
- Unity Engine
FAccelByteModelsMoveUserItemDataRequest MoveItem = {};
MoveItem.Qty = 1;
MoveItem.SlotId = FString("SomeSlotId");
MoveItem.SourceItemId = FString("SomeSourceItemId");
FAccelByteModelsMoveUserItemsBetweenInventoriesRequest MoveItemsRequest = {};
MoveItemsRequest.SrcInventoryId = FString("SomeSourceInventoryId");
MoveItemsRequest.Items.Add(MoveItem);
FString DestinationInventoryId = FString("SomeDestinationInventoryId");
FAccelByteModelsMoveUserItemsBetweenInventoriesResponse OutResult;
const FApiClientPtr ApiClient = AccelByteOnlineSubsystemPtr->GetApiClient();
ApiClient->Inventory.MoveItemsBetweenInventories(DestinationInventoryId, MoveItemsRequest,
THandler<FAccelByteModelsMoveUserItemsBetweenInventoriesResponse>::CreateLambda([&](const FAccelByteModelsMoveUserItemsBetweenInventoriesResponse& Result)
{
OutResult = Result;
// Do something if MoveItemsBetweenInventories is successful
})
, FErrorHandler::CreateLambda([&](const int32 ErrorCode, const FString& ErrorMessage)
{
// Do something if MoveItemsBetweenInventories has an error
}));
string sourceInventoryId = "SomeSourceInventoryId";
string destinationInventoryId = "SomeDestinationInventoryId";
var payload = new MoveUserItemsBetweenInventoriesPayload[]
{
new MoveUserItemsBetweenInventoriesPayload(expectedQty, slotId, sourceItemId)
};
Result<MoveUserItemsBetweenInventoriesResponse> moveResult = null;
AccelByteSDK.GetClientRegistry().GetApi().GetInventory().MoveItemsBetweenInventories(destinationInventoryId, sourceInventoryId, payload, result =>
{
if (result.IsError)
{
// Do something if MoveItemsBetweenInventories has an error
UnityEngine.Debug.Log($"Failed to move item [{result.Error.Code}]:{result.Error.Message}");
return;
}
// Do something if MoveItemsBetweenInventories is success
moveResult = result;
});