> For the complete documentation index, see [llms.txt](https://fish-networking.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fish-networking.gitbook.io/docs/guides/features/network-communication/synchronizing/synchashset.md).

# SyncHashSet

Callbacks for SyncHashSet are similar to SyncList. And like other synchronization types changes are set immediately before the callback occurs.

```csharp
private readonly SyncHashSet<int> _myCollection = new SyncHashSet<int>();

private void Awake()
{
    _myCollection.OnChange += _myCollection_OnChange;
}

private void FixedUpdate()
{
    // You can modify a synchashset as you would any other hashset.
    _myCollection.Add(Time.frameCount);
}

/* Like SyncVars the callback offers an asServer option
 * to indicate if the callback is occurring on the server
 * or the client. As SyncVars do, changes have already been
 * made to the collection before the callback occurs. */
private void _myCollection_OnChange(SyncHashSetOperation op, int item, bool asServer)
{
    switch (op)
    {
        /* An object was added to the hashset. Item is
         * is the added object. */
        case SyncHashSetOperation.Add:
            break;
        /* An object has been removed from the hashset. Item
         * is the removed object. */
        case SyncHashSetOperation.Remove:
            break;
        /* The hashset has been cleared. 
         * Item will be default. */
        case SyncHashSetOperation.Clear:
            break;
        /* An entry in the hashset has been updated. 
         * When this occurs the item is removed
         * and added. Item will be the new value.
         * Item will likely need a custom comparer
         * for this to function properly. */
        case SyncHashSetOperation.Update:
            break;            
        /* When complete calls all changes have been
        * made to the collection. You may use this
        * to refresh information in relation to
        * the changes, rather than doing so
        * after every entry change. All values are
        * default for this operation. */
        case SyncHashSetOperation.Complete:
            break;
    }
}

```

{% hint style="danger" %}
If you are using this SyncType with a container, such as a class or structure, and want to modify values within that container, you must set the value dirty. See the example below.
{% endhint %}

```csharp
[System.Serializable]
private struct MyContainer
{
    public string PlayerName;
    public int Level;
}

private readonly SyncHashSet<MyContainer> _containers = new();
private MyContainer _containerReference = new();

private void Awake()
{
    _containerReference.Level = 5;
    _containers.Add(_containerReference);
}

[Server]
private void ModifyPlayer()
{
    
    // This will change the value locally but it will not synchronize to clients.
    _containerReference.Level = 10;
    // The value must be set dirty to force a synchronization.
    _containers.Dirty(_containerReference);
}
```


---

# 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, and the optional `goal` query parameter:

```
GET https://fish-networking.gitbook.io/docs/guides/features/network-communication/synchronizing/synchashset.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
