> For the complete documentation index, see [llms.txt](https://netick.gitbook.io/v1/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://netick.gitbook.io/v1/change-callback.md).

# Change Callback

## For Properties

You can have a method get called whenever a networked property changes, which is very useful. To do that, add the attribute `[OnChanged]` to the method and give it the name of the property. The method must have one parameter of the same type of the property which would contain its previous value.

Example:

```csharp
[Networked]
public int Health { get; set; }

[OnChanged(nameof(Health ))]
private void OnHealthChanged(int previous)
{
        // Something that happens when the Health property changes
}
```

## **For Arrays**

If you have an array and want a callback for when an element changes, you can do so as follows:

Example:

```csharp
[Networked(size: 10)]
public NetworkArray<int> Items { get; set; }

[OnChanged(nameof(Items))]
private void ArrayChanged(int index)
{
      // Something that happens when an element of the array changes
}
```

The difference here to a variable property is that the callback method must have an index parameter that points to the changed element.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://netick.gitbook.io/v1/change-callback.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
