# Unlockables

**URL:** https://heroiclabs.com/docs/hiro/unity/unlockables/
**Keywords:** unlockables, hiro
**Categories:** hiro, unity, unlockables

---


# Unlockables

Read more about the Unlockables system in Hiro [here](../../concepts/unlockables/).

## Initializing the unlockables system

The unlockables system relies on the [Nakama System](../getting-started/nakama-system) and an `ILogger`, both must be passed in as dependencies via the constructor.

```csharp
var unlockablesSystem = new UnlockablesSystem(logger, nakamaSystem);
systems.Add(unlockablesSystem);
```

## Subscribing to changes in the unlockables system

You can listen for changes in the unlockables system so that you can respond appropriately, such as updating the UI, by implementing the `IObserver` pattern, or use the `SystemObserver<T>` type which handles it for you.

```csharp
var disposer = SystemObserver<UnlockablesSystem>.Create(unlockablesSystem, system => {
    Instance.Logger.Info($"System updated.");

    // Update UI elements etc as necessary here...
});
```

## Refreshing the unlockables system

To ensure the unlockables system has the latest information from Nakama you can refresh it.

```csharp
await unlockablesSystem.RefreshAsync();
```

## Listing available unlockables

You can list available unlockables.

```csharp
foreach (var unlockable in unlockablesSystem.Unlockables)
{
    Debug.Log($"{unlockable.Name} - {unlockable.Description}. Cost:");

    foreach (var currencyKvp in unlockable.Cost.Currencies)
    {
        Debug.Log($"{currencyKvp.Key}: {currencyKvp.Value}");
    }
    
    foreach (var itemKvp in unlockable.Cost.Items)
    {
        Debug.Log($"{itemKvp.Key}: {itemKvp.Value}");
    }
}
```

## Claiming an unlockable reward

You can claim an unlockable reward.

```csharp
var unlockablesReward = await unlockablesSystem.ClaimAsync("<instanceId>");

Debug.Log("Collected reward:");

foreach (var currencyKvp in unlockablesReward.Reward.Currencies)
{
    Debug.Log($"{currencyKvp.Key}: {currencyKvp.Value}");
}

foreach (var consumableKvp in unlockablesReward.Reward.Items)
{
    Debug.Log($"{consumableKvp.Key}: {consumableKvp.Value}");
}

foreach (var energyKvp in unlockablesReward.Reward.Energies)
{
    Debug.Log($"{energyKvp.Key}: {energyKvp.Value}");
}
```

## Purchasing a slot

You can purchase an additional unlockable slot.

```csharp
await unlockablesSystem.PurchaseSlotAsync();
```

## Purchasing an unlock

You can purchase an unlock of a slot.

```csharp
await unlockablesSystem.PurchaseUnlockAsync("<instanceId>");
```

## Begin unlocking a slot

You can begin unlocking a slot.

```csharp
await unlockablesSystem.UnlockStartAsync("<instanceId>");
```

## Creating an unlockable

You can create an unlockable.

```csharp
await unlockablesSystem.CreateAsync();
```

## Inspecting the overflow slot

You can inspect the overflow slot.

```csharp
Debug.Log($"{unlockablesSystem.Overflow.Name} - {unlockablesSystem.Overflow.Description}");
```
