> For the complete documentation index, see [llms.txt](https://mirror-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://mirror-networking.gitbook.io/docs/manual/guides/communications/network-messages.md).

# Network Messages

For the most part we recommend the high level [Commands and RPC](/docs/manual/guides/communications/remote-actions.md) calls and [SyncVar](/docs/manual/guides/synchronization/syncvars.md), but you can also send low level network messages. This can be useful if you want clients to send messages that are not tied to game objects, such as logging, analytics or profiling information.

There is a public interface called NetworkMessage that you can extend to make serializable network message structs. Serialize and Deserialize methods are automatically generated for network messages by Mirror, and they can efficiently handle any [supported mirror type](/docs/manual/guides/data-types.md), but if you need to you can implement your own serialization methods by following our [serialization guide](/docs/manual/guides/serialization.md). Some other useful tips for implementing low-level messages:

* Make sure all your members are public fields. Weaver doesn't serialize properties.
* If you need classes or complex containers such as `List<T>` and `Dictionary<T,K>`, you must implement the Read and Write methods yourself.

To send a message, use the `Send()` method on the NetworkClient, NetworkServer, and NetworkConnection classes, which all work the same way using a message struct that is derived from NetworkMessage. The code below demonstrates how to send and handle a message:

To declare a custom network message class and use it:

```csharp
using UnityEngine;
using Mirror;

public class Scores : MonoBehaviour
{
    public struct ScoreMessage : NetworkMessage
    {
        public int score;
        public Vector3 scorePos;
        public int lives;
    }

    public void SendScore(int score, Vector3 scorePos, int lives)
    {
        ScoreMessage msg = new ScoreMessage()
        {
            score = score,
            scorePos = scorePos,
            lives = lives
        };

        NetworkServer.SendToAll(msg);
    }

    public void SetupClient()
    {
        NetworkClient.RegisterHandler<ScoreMessage>(OnScore);
        NetworkClient.Connect("localhost");
    }

    public void OnScore(ScoreMessage msg)
    {
        Debug.Log("OnScoreMessage " + msg.score);
    }
}
```


---

# 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://mirror-networking.gitbook.io/docs/manual/guides/communications/network-messages.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.
