Closed
Description
Description
I'm currently having an issue with Unnamed Messages that going by documentation would suggest this is a bug. Forgive me if I've misunderstood the intent of this part of the API.
The summary for UnnamedMessageDelegate
describes the parameter clientId
as:
The clientId that sent the message
However, when subscribing to CustomMessagingManager.OnUnnamedMessage
, the clientId
parameter passed into the invoked subscriber seems to be the value of the receiving user's client ID, not the sender of the message.
To Reproduce
- Subscribe to the
CustomMessagingManager.OnUnnamedMessage
event. - Send a message from the host using
CustomMessagingManager.SendUnnamedMessage
passing null to send to all clients. - When the client's subscriber is invoked observe that the value of
clientId
is not the sender but is equivalent toNetworkManager.LocalClientId
Environment
- OS: Windows 10
- Unity Version: 2020.3.14f1
- MLAPI Version: 0.1.0
Additional context
This was tested between the Unity Editor running as host and a build on the same machine as client.
The MonoBehaviour class I used to test this is below.
using System.IO;
using MLAPI.Messaging;
using MLAPI.Serialization.Pooled;
using UnityEngine;
public class UnnamedMessageTest : MonoBehaviour
{
[SerializeField]
private string _messageContent = "Hello";
private void Awake()
{
CustomMessagingManager.OnUnnamedMessage += HandleUnnamedMessage;
}
[ContextMenu("Send")]
private void Send()
{
using var buffer = PooledNetworkBuffer.Get();
using var writer = PooledNetworkWriter.Get(buffer);
writer.WriteString(_messageContent);
// Send to all clients
CustomMessagingManager.SendUnnamedMessage(null, buffer);
}
private void HandleUnnamedMessage(ulong sender, Stream stream)
{
using var reader = PooledNetworkReader.Get(stream);
var content = reader.ReadString();
Debug.LogFormat("Received unnamed message from sender {0} with content {1}", sender, content);
}
}