Skip to content

NetworkList<T>.Contains(T) return value is inverted #1352

Closed
@DapperDino

Description

@DapperDino

Describe the bug
When calling NetworkList<T>.Contains(T) it is returning the opposite bool of what I'm expecting.

To Reproduce
Steps to reproduce the behavior:

  1. Add an element to a NetworkList
  2. Debug.Log the return value from: NetworkList<T>.Contains(T) passing in the element you added
  3. Debug.Log the return value from: NetworkList<T>.Contains(T) passing in an element you didn't add
  4. See log output

Actual outcome
False
True

Expected outcome
True
False

Screenshots
Looking at the source, it is returning true if the index of the element is -1, otherwise false. I'm pretty sure this is the cause of the issue.

public bool Contains(T item)
{
    int index = NativeArrayExtensions.IndexOf(m_List, item);
    return index == -1;
}

Environment (please complete the following information):

  • OS: [Windows 10]
  • Unity Version: [2021.1]
  • Netcode Version: [v1.0.0-pre.2]

Metadata

Metadata

Labels

priority:highThis issue has high priority and we are focusing to resolve ittype:bugBug Report

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions