# Observe System Changes

**URL:** https://heroiclabs.com/docs/hiro/unity/getting-started/observing-system-changes/
**Summary:** Learn how to observe changes in Hiro Systems.
**Keywords:** observe system changes, hiro, observing system changes
**Categories:** hiro, unity, observing-system-changes

---


# Observe System Changes

Hiro enables you to observe changes to the state of any systems used by using the `SystemObserver` helper or by subscribing an appropriate `IObserver` to that system. This can be useful for updating things such as UI in a reactive way.

The following example demonstrates how changes in the [`NakamaSystem`](../nakama-system/) can be observed.

## Using the SystemObserver

Using the `SystemObserver` helper class allows you to bind an action to be triggered whenever the system values change.

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

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

## Implementing the IObserver interface

Alternatively you can implement the `IObserver<T>` interface. This approach gives you more control and also allows you to observe different system states, such as if the system encounters an error.

```csharp
public class NakamaSystemObserver : IObserver<NakamaSystem>
{
    public NakamaSystemObserver(NakamaSystem nakamaSystem)
    {
        nakamaSystem.Subscribe(this);
    }

    public void OnCompleted()
    {
        Debug.Log("OnCompleted called");
    }

    public void OnError(Exception error)
    {
        Debug.LogError($"OnError called: {error.Message}");
    }

    public void OnNext(NakamaSystem nakamaSystem)
    {
        Debug.Log($"NakamaSystem updated for user {nakamaSystem.Account.Username}");
    }
}
```

Instantiate and use the class, for example in the `GameCoordinator`:

```csharp
var nakamaSystemObserver = new NakamaSystemObserver(_nakamaSystem);
```
