# Why events dont work the same on different clients in the nakama clients

**URL:** <https://forum.heroiclabs.com/t/why-events-dont-work-the-same-on-different-clients-in-the-nakama-clients/5938>\
**Category:** Client Libraries\
**Created:** [January 14, 2025, 9:36am UTC](https://forum.heroiclabs.com/t/why-events-dont-work-the-same-on-different-clients-in-the-nakama-clients/5938 "2025-01-14T09:36:07Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![virtouso](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/virtouso/32/679_2.png) [@virtouso](https://forum.heroiclabs.com/u/virtouso)\
**Post date:** [January 14, 2025, 9:36am UTC](https://forum.heroiclabs.com/t/why-events-dont-work-the-same-on-different-clients-in-the-nakama-clients/5938/1 "2025-01-14T09:36:07Z")

</div>

on unity Client there Is Event called “OnPressenceUpdate”. When match is created and the presence is updated, one client receives on single Event with added 2 players to the match but another receives 2 events that on each of them on played has joined.

is there any reason for this or is it just a technical limitation?

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [January 14, 2025, 12:26pm UTC](https://forum.heroiclabs.com/t/why-events-dont-work-the-same-on-different-clients-in-the-nakama-clients/5938/2 "2025-01-14T12:26:15Z")

</div>

Hello @virtouso,

Can you be more specific on what events or SDKs you’re observing these differences?

---

<div class="post-metadata">

**Author:** ![virtouso](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/virtouso/32/679_2.png) [@virtouso](https://forum.heroiclabs.com/u/virtouso)\
**Post date:** [January 14, 2025, 12:31pm UTC](https://forum.heroiclabs.com/t/why-events-dont-work-the-same-on-different-clients-in-the-nakama-clients/5938/3 "2025-01-14T12:31:49Z")

</div>

the client sdk is unity. and the callback is " socket.ReceivedMatchPresence"

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [January 14, 2025, 12:55pm UTC](https://forum.heroiclabs.com/t/why-events-dont-work-the-same-on-different-clients-in-the-nakama-clients/5938/4 "2025-01-14T12:55:16Z")

</div>

> [@virtouso](#):
>
> OnPressenceUpdate

Where can I find this event or callback?

---

<div class="post-metadata">

**Author:** ![virtouso](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/virtouso/32/679_2.png) [@virtouso](https://forum.heroiclabs.com/u/virtouso)\
**Post date:** [January 14, 2025, 1:27pm UTC](https://forum.heroiclabs.com/t/why-events-dont-work-the-same-on-different-clients-in-the-nakama-clients/5938/5 "2025-01-14T13:27:20Z")

</div>

```
public class NakamaAutomaticMatch : MonoBehaviour
{
private string emailText = "";
private string inputText = "";

private const string scheme = "http";
private const string host = "localhost";
private const int port = 7350;
private const string serverKey = "defaultkey";

private IClient client;
private ISocket socket;
private ISession session;

private IMatch match;
private string matchId = "";
private string joinMatchId = "";

void OnGUI()
{
    emailText = GUILayout.TextField(emailText, 25, GUILayout.Width(200));
    inputText = GUILayout.TextField(inputText, 25, GUILayout.Width(200));

    GUILayout.Space(10);

    if (GUILayout.Button("Auth", GUILayout.Width(100)))
    {
        Authenticate();
    }

    if (GUILayout.Button("Create", GUILayout.Width(100)))
    {
        CreateMatch();
    }

    if (GUILayout.Button("Send", GUILayout.Width(100)))
    {
        SendMessage(inputText);
    }

    if (GUILayout.Button("Leave", GUILayout.Width(100)))
    {
        socket.LeaveMatchAsync(match);
    }
}

private async Task Authenticate()
{
    client = new Client(scheme, host, port, serverKey);
    socket = Nakama.Socket.From(client);

    // Authenticate with device ID
    session = await client.AuthenticateEmailAsync(emailText, "123456789");

    Debug.LogError($"Authenticated: {session.UserId}");

    // Connect socket
    await socket.ConnectAsync(session);
    Debug.LogError("Socket connected.");

    // Listen to match data
    socket.ReceivedMatchState += OnReceivedMatchState;
    
    socket.ReceivedMatchmakerMatched += OnMatched;
    socket.ReceivedMatchPresence += OnMatchPresence;
  
}

private void OnMatchPresence(IMatchPresenceEvent message)
{
    Debug.LogError($"{message.MatchId} presence updated");

    foreach (var item in message.Joins)
    {
        Debug.LogError($"{item.Username} joined the match. {item.Persistence} {item.Status}");
    }

    foreach (var item in message.Leaves)
    {
        Debug.LogError($"{item.Username} left the match {item.Persistence} {item.Status}"); 
    }
}

private async void OnMatched(IMatchmakerMatched newMatch)
{
    Debug.LogError("matched");
    Debug.LogError(newMatch.MatchId);
    match = await socket.JoinMatchAsync(newMatch);
}

private void OnReceivedMatchState(IMatchState matchState)
{
    string receivedMessage = System.Text.Encoding.UTF8.GetString(matchState.State);
    Debug.LogError($"Received from match: {receivedMessage}");
}

private async void SendMessage(string message)
{
    if (match != null)
    {
        byte[] data = System.Text.Encoding.UTF8.GetBytes(message);
        await socket.SendMatchStateAsync(match.Id, 0, data);
        Debug.LogError($"Sent message: {message}");
    }
}

private async void CreateMatch()
{
    var ticket = await socket.AddMatchmakerAsync("*", 2, 2);

    Debug.LogError($"ticket id:{ticket.Ticket}");
}

}

```

its my whole sample code.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [January 15, 2025, 11:10am UTC](https://forum.heroiclabs.com/t/why-events-dont-work-the-same-on-different-clients-in-the-nakama-clients/5938/6 "2025-01-15T11:10:42Z")

</div>

Apologies but I’m still not sure to which two callbacks you’re referring to, what issue you’re facing or what’s the question.

---

<div class="post-metadata">

**Author:** ![virtouso](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/virtouso/32/679_2.png) [@virtouso](https://forum.heroiclabs.com/u/virtouso)\
**Post date:** [January 15, 2025, 4:25pm UTC](https://forum.heroiclabs.com/t/why-events-dont-work-the-same-on-different-clients-in-the-nakama-clients/5938/7 "2025-01-15T16:25:18Z")

</div>

i have to send the logs here to show the problem. i will do it.

---

<div class="post-metadata">

**Author:** ![virtouso](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/virtouso/32/679_2.png) [@virtouso](https://forum.heroiclabs.com/u/virtouso)\
**Post date:** [January 21, 2025, 7:54am UTC](https://forum.heroiclabs.com/t/why-events-dont-work-the-same-on-different-clients-in-the-nakama-clients/5938/8 "2025-01-21T07:54:42Z")

</div>

in previous examlpe:

```
_socket.ReceivedMatchPresence += OnMatchPresence;

  private void OnMatchPresence(IMatchPresenceEvent message)
  {
      Debug.LogError($"{message.MatchId} presence updated");

      foreach (var item in message.Joins)
      {
          Debug.LogError($"{item.Username} joined the match. {item.Persistence} {item.Status}");
      }

      foreach (var item in message.Leaves)
      {
          Debug.LogError($"{item.Username} left the match {item.Persistence} {item.Status}");
      }
  }

```

result of the above code for the first matched user:

```
    cb97c750-d4a4-4c55-87cc-e24dcbe8bcfd. presence updated
    vibFUuQxjp joined the match. False  
    LvpIOPlZSr joined the match. False  
    
    result of above code for seconds matched user:
    cb97c750-d4a4-4c55-87cc-e24dcbe8bcfd. presence updated
    vibFUuQxjp joined the match. False  
    cb97c750-d4a4-4c55-87cc-e24dcbe8bcfd. presence updated
    LvpIOPlZSr joined the match. False  

```

it means the event is called for seconds player 2 times but separately for each players.

i hope this clarifies.

---

<div class="post-metadata">

**Author:** ![sesposito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.heroiclabs.com/sesposito/32/2594_2.png) [@sesposito](https://forum.heroiclabs.com/u/sesposito)\
**Post date:** [January 21, 2025, 2:30pm UTC](https://forum.heroiclabs.com/t/why-events-dont-work-the-same-on-different-clients-in-the-nakama-clients/5938/9 "2025-01-21T14:30:56Z")

</div>

So if I understood correctly, the question is why you sometimes see two separate events with a join each, and sometimes a single event with both joins?

This is not an issue nor a technical limitation, but rather an optimization, events can be batched within the same call or not depending on how the server processes them.
