> 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/prediction/custom-comparers.md).

# Custom Comparers

You may see an error in the console about a type requiring a custom comparer. For example, generics and arrays specifically must have a custom comparer provided.

```csharp
/* For example, this will create an error stating
* byte[] needs a custom comparer. */
public struct MoveData : IReplicateData
{
    public Vector2 MoveDirection;
    public byte[] CustomData;
    // rest omitted..
}
```

While a comparer could be made automatically for the type byte\[], we still require you to create your own as we may not know exactly how you want to compare these types. The code below compares byte arrays by iterating every byte to check for mismatches. Given how often prediction data sends, this could potentially burden the processor.

```csharp
[CustomComparer]
public static bool CompareByteArray(byte[] a, byte[] b)
{
    bool aNull = (a is null);
    bool bNull = (b is null);
    // Both are null.
    if (aNull && bNull)
        return true;
    // One is null, other is not.
    if (aNull != bNull)
        return false;
    // Not same lengths, cannot match.
    if (a.Length != b.Length)
        return false;
​
    // Both not null and same length, compare bytes.
    int length = a.Length;
    for (int i = 0; i < length; i++)
    {
        // Differs.
        if (a[i] != b[i])
            return false;
    }
​
    // Fall through, if here everything matches.
    return true;
}
```

The above code is a working example of how to create a custom comparer, but it may not be the most ideal comparer for your needs; this is why we require you to make your own comparer for such types.

Creating your own comparer is simple. Make a new static method with any name and boolean as the return type. Decorate the method with the **\[CustomComparer]** attribute. There must also be two parameters, each being the type you want to compare. The method logic can contain whichever code you like


---

# 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/prediction/custom-comparers.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.
