fix: replace null-coalescencing and null-conditional operators [MTT-7125] by LPLafontaineB · Pull Request #867 · Unity-Technologies/com.unity.multiplayer.samples.coop
Description
This PR replaces occurrences of the null-coalesing (??=) and null-conditional (?.) operators in the project. These operators can cause issues when used with types inheriting UnityEngine.Object because that type redefines the == operator to define when an object is null. This redefinition applies to regular null checks (if foo == null) but not to those operators, thus this could lead to unexpected behaviour.
While those operators were safely used within Boss Room, only with types that were not inheriting UnityEngine.Object, we decided to remove most usages for consistency. This will also help avoid accidental mistakes, such as a user reusing a part of this code, but modifying it so that one of those operators are used with a UnityEngine.Object.
The only cases where we kept the null-conditional operator were with events/delegates/actions, for which there is no risk of confusion.
Issue Number(s)
Contribution checklist
- Tests have been added for boss room and/or utilities pack
- Release notes have been added to the project changelog file and/or package changelog file
- Pull request has a meaningful description of its purpose
- All commits are accompanied by meaningful commit messages
- JIRA ticket ID is in the PR title or at least one commit message
- Include the ticket ID number within the body message of the PR to create a hyperlink
- An Index entry has been added in readme.md if applicable