Quickstart_Cpp
Review draft. This source page has not completed website editorial and release-specific verification.
# C++ Quickstart
The following examples use the public Inventory Director headers and APIs. Include the concrete public headers used by the code in your module.
#include "InventoryComponent.h"#include "InventorySubsystem.h"#include "InventoryItemDefinition.h"
UInventoryComponent* Inventory = /* obtain the component */;UInventoryItemDefinition* Potion = /* obtain a loaded definition */;
const int32 Count = Inventory->GetItemCount(Potion);const FInventoryMutationResult Added = Inventory->AddItem(Potion, 2);if (Added.IsChanged()){ const FInventoryMutationResult Removed = Inventory->RemoveItem(Potion, 1);}The native committed-change delegate is available through OnInventoryChanged():
Inventory->OnInventoryChanged().AddLambda( [](const FInventoryChangedEvent& Event) { // Read Event.InventoryIdentity, Event.Status, and Event.SlotChanges. });The Game Instance subsystem provides identity lookup and transfer:
UInventorySubsystem* Subsystem = /* obtain the Game Instance subsystem */;const FInventoryTargetIdentity Source = FInventoryTargetIdentity::MakePersistent(FName(TEXT("Player.Main")));const FInventoryTargetIdentity Destination = FInventoryTargetIdentity::MakePersistent(FName(TEXT("Chest.Castle.Armory.03")));const FInventoryMutationResult Transfer = Subsystem->TransferItem(Source, Destination, Potion, 1);Pool selection uses the caller’s stream:
FRandomStream Stream(12345);const FInventoryPoolSelectionResult Draw = Subsystem->SelectRandomItemFromPool(Pool, Stream);Semantic persistence is independent of disk and slot orchestration:
FInventoryPersistenceSnapshot Snapshot;const FInventoryPersistenceResult Captured = Subsystem->CapturePersistenceSnapshot(Snapshot);
if (Captured.IsSuccess()){ const FInventoryPersistenceResult Restored = Subsystem->RestorePersistenceSnapshot(Snapshot);}The exact subsystem acquisition mechanism depends on the owning Game Instance. Optional SaveGame adaptation is provided by DirectorBridge and does not change these core APIs.
For optional Probability-owned pool selection, use DirectorBridge’s Inventory.Probability integration and FDirectorBridgeInventoryProbabilityService::SelectPoolEntrySequential or SelectPoolEntryKeyed. The service receives the owning UGameInstance, Inventory-authored pool, Probability StreamId, and (for keyed calls) a stable DecisionKey. InventoryDirectorProbabilityBridge is retired. Inventory’s native FRandomStream pool APIs continue to work without DirectorBridge or Probability Director; see Probability Integration.
Runtime Inspector (V1.1)
Section titled “Runtime Inspector (V1.1)”During PIE/SIE open Tools → Director Suite → Runtime Inspectors → Inventory Director Runtime Inspector to inspect the selected authority; this surface is strictly read-only. Use Tools → Director Suite → Runtime Controls → Inventory Director Runtime Controls for explicit operations through the existing public component/subsystem APIs. Advanced Debug Override is unavailable because Inventory has no policy-only bypass. Controls do not write authored assets or save automatically. See Editor Tools for operation scope and journal behavior.