Skip to content

NetworkList not sending custom message #1313

@KirkGamesLLC

Description

@KirkGamesLLC

Describe the bug

I defined this component with a NetworkList field for a custom message

` public class Chat : NetworkBehaviour
{
public NetworkList chatMessagesNetworkList;

    public override void OnNetworkSpawn()
    {
        if (IsServer)
        {
            chatMessagesNetworkList = new NetworkList<ChatNetMessage>();
        }

        chatMessagesNetworkList.OnListChanged += OnListChanged;
    }

    [ServerRpc]
    public void SendChatMessageServerRpc(ulong clientId, string playerName = "", string message = "")
    {
        AddChatMessage(clientId, playerName, message);
    }

    public void AddChatMessage(ulong clientId, string playerName = "", string message = "")
    {
         var chatNetMessage = new ChatNetMessage(clientId, playerName, message);

        chatMessagesNetworkList.Add(chatNetMessage);
    }

...
`

The message
` public struct ChatNetMessage : INetworkSerializable, IEquatable
{
public ulong clientId;

        public bool Equals(ChatNetMessage other)
        {
            return this.clientId == other.clientId && this.playerName == other.playerName && this.message == other.message;
        }


        public ChatNetMessage(ulong clientId, FixedString32Bytes playerName, FixedString32Bytes message)
        {
            this.clientId = clientId;
            this.playerName = playerName;
            this.message = message;
        }

        //public string playerName;
        public FixedString32Bytes playerName;
        //public string message;
        public FixedString32Bytes message;

        void INetworkSerializable.NetworkSerialize<T>(BufferSerializer<T> serializer)
        {
            //Debug.Log($"<color=lime>ChatNetMessage Serializing</color>");
            serializer.SerializeValue(ref clientId);
            serializer.SerializeValue<FixedString32Bytes>(ref playerName);
            serializer.SerializeValue<FixedString32Bytes>(ref message);
        }
    }

`
To Reproduce
when I add a message (from the Host) it doesn't serialize the message and send it to the client

Actual outcome
Server does not serialize the message. No errors reported.

Expected outcome
Server should serialize the message and send it to the client should receive the message and OnListChanged event should fire.

.

Environment (please complete the following information):

  • OS: MacOS 10.15.7
  • Unity Version: 2020.3.15f2
  • Netcode Version: #develop
  • Netcode Commit: latest as of today

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions