Skip to content

NetworkedList invokes invalid OnChanged events in non-host mode #421

@LukeStampfli

Description

@LukeStampfli

Describe the bug
When using a NetworkedList in Server mode, newly connected clients receive OnChanged events for existing items in that NetworkedList. When running in Host mode this does not occur.

To Reproduce
Steps to reproduce the behavior:

  1. Create a NetworkedObject, Add the following NetworkedBehaviour to it:
public class Test : NetworkedBehaviour
{
    private NetworkedList<float> test = new NetworkedList<float>();
    public override void NetworkStart()
    {
        test.OnListChanged += TestOnOnListChanged;

        if (IsServer)
        {
            Debug.Log("Server Here!");
            for (int i = 0; i < 4; i++)
            {
                test.Add(i);
            }
        }
    }

    private void TestOnOnListChanged(NetworkedListEvent<float> changeevent)
    {
        Debug.Log($"eventType: {changeevent.eventType} index: {changeevent.index} value: {changeevent.value} count: {test.Count}");
    }
}
  1. Add it to the scene and to the NetworkingManager.
  2. Enter playmode as Server and connect a Client and compare the two logs.
  3. The Server shows:
    image
    The Client shows:
    image
    When running the Server as host instead the client shows receives no change events (no debug logs in console)

Expected behavior
The client should not be invoking OnChange events when the NetworkedList gets initialized for both host and server mode. The behavior should also be consistent between the two.

Environment (please complete the following information):

  • OS: Windows 10
  • Unity Version: 2020.2.0f1
  • MLAPI Version: develop
  • MLAPI Commit: 29b1616

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions