# Streaks

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

---


# Streaks

Read more about the Streak system in Hiro [here](../../concepts/streaks/).

## Initializing the streaks system

The streaks 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 streaksSystem = new StreaksSystem(logger, nakamaSystem);
systems.Add(streaksSystem);
```

## Subscribing to changes in the streaks system

You can listen for changes in the streak 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<StreaksSystem>.Create(streaksSystem, system => {
  Instance.Logger.Info($"Streaks system updated.");

  // Update UI or handle changes here...
});
```

## Refreshing the streaks system

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

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

## Listing streaks

You can list the current streaks for the user:

```csharp
foreach (var (key, streak) in streaksSystem.Streaks)
{
    Debug.Log($"{key}: {streak.CurrentStreakValue}");
}
```

## Claiming Streaks Rewards

Players can claim streak rewards using the `ClaimAsync` method, passing the streak IDs.

```csharp
await streaksSystem.ClaimAsync(new List<string> { "daily_login", "weekly_win" });
```

## Resetting Streaks

To reset specific streaks for a player, use the `ResetAsync` method:

```csharp
await streaksSystem.ResetAsync(new List<string> { "daily_login", "weekly_win" });
```

## Updating Streaks

You can manually update streaks for a player by passing a dictionary of streak names and new values:

```csharp
var streaksToUpdate = new Dictionary<string, long>
{
    { "daily_login", 10 },
    { "weekly_win", 3 }
};

await streaksSystem.UpdateAsync(streaksToUpdate);
```

## Additional information

- [Mage Mayhem sample project](../../../../sample-projects/games/mage-mayhem)
