> For the complete documentation index, see [llms.txt](https://docs.coherence.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.coherence.io/manual/networking-state-changes/value-sync-attribute.md).

# \[OnValueSynced]

This attribute triggers a method on remote entities when the variable is changed by the state authority.

Works with [any type supported by coherence](/manual/networking-state-changes/supported-types.md).

{% hint style="info" %}
The callback method will be called only for remote instances and **not on the state authority**. We recommend using [properties with a backing field](https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/properties#properties-with-backing-fields) for this.
{% endhint %}

### Usage

Let's start with a simple example:

```csharp
using Coherence.Toolkit;
using UnityEngine;
using UnityEngine.UI;

public class Player : MonoBehaviour
{
    [OnValueSynced(nameof(UpdateHealthLabel))]
    public float Health;

    public Text HealthLabel;

    public void UpdateHealthLabel(float oldHealth, float newHealth)
    {
        HealthLabel.text = newHealth.ToString();
        Debug.Log($"Player HP changed by: {newHealth - oldHealth}");
    }
}
```

Whenever the value of the `Health` field gets updated (synced with its simulated version) the `UpdateHealthLabel` will be called automatically, changing the health label text and printing a log with a health difference.

You can also apply the attribute on the callback method, and give the name of the field instead:

```csharp
[OnValueSynced(nameof(Health))]
public void UpdateHealthLabel(float oldHealth, float newHealth)
```

There's no behaviour difference — it's just a matter of style and preference.

{% hint style="success" %}
For the OnValueSynced attribute to work, the given field or property has to be synchronized over the network, via the [Sync attribute](/manual/networking-state-changes/sync-and-command-attributes.md) or via the [Configure window](/getting-started/setup-a-project/prefab-setup.md).
{% endhint %}

{% hint style="warning" %}
The `OnValueSynced` attribute targets only members within the given class. That is, there's no way to be notified about a change in the value of a Unity built-in component, like `transform.position`.
{% endhint %}
