gameMessage.sender is always 1

I’m sending the gameMessager.sender like this:

session.getPlayers().forEach((thisPlayer, playerId) => {

                if (playerId != gameMessage.sender) {
let messageToSend = session.newTextGameMessage(gameMessage.opCode, gameMessage.sender.toString(), gameMessage.payload);

                session.getLogger().info("[app] Shoot from"+ gameMessage.sender.toString()); //output: Shoot from2

                    session.sendMessage(messageToSend,thisPlayer.peerId)
}
})

but when I logged the e.sender in unity:

private void OnDataReceived(object sender, DataReceivedEventArgs e)
    {
          Debug.Log($"sender:{e.Sender}");
}

It is always 1, no matter what I do. I shoot from anyone player and it always show “sender:1”

At a guess, have you tried replacing gameMessage.sender.toString with just gameMessage.sender?

This should be the peerId as per https://docs.aws.amazon.com/gamelift/latest/developerguide/realtime-script-objects.html which should be all you need.

Mostly this field is set and passed through and should be spec’d as an int I believe

The problem persists. It still sending 1 but it print the correct Sender before.

I did this:

session.getLogger().info("[app] SendStringToClient: " + messageToSend.sender.toString()) 

And there the sender still been another number. The number change to one later it is send or when is received on onDataReceived() in the client. I don’t know why