Skip to content

Commit

Permalink
Update USP0022.md
Browse files Browse the repository at this point in the history
  • Loading branch information
sailro authored May 24, 2024
1 parent fcaa655 commit f2a944c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions doc/USP0022.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# USP0022 Prefer reference equality
# USP0022 Unity objects should not use if null coalescing

We have a dedicated diagnostic `UNT0029` to prevent is-null check with `UnityEngine.Object`. But `IDE0270` will suggest to use is-null check over reference equality method.

Expand Down Expand Up @@ -29,4 +29,4 @@ Under normal circumstances, `if (item == null) throw new System.InvalidOperation

## Why do we suppress this diagnostic?

Unity has overridden the `==` operator for `UnityEngine.Object`. If you use the `==` operator to compare a `UnityEngine.Object` to null, it will return true if the `UnityEngine.Object` is destroyed, even if the object itself isn't actually null. The `??` operator cannot be overridden in this way, and therefore behaves inconsistently with the `==` operator, because it checks for null in a different way.
Unity has overridden the `==` operator for `UnityEngine.Object`. If you use the `==` operator to compare a `UnityEngine.Object` to null, it will return true if the `UnityEngine.Object` is destroyed, even if the object itself isn't actually null. The `??` operator cannot be overridden in this way, and therefore behaves inconsistently with the `==` operator, because it checks for null in a different way.

0 comments on commit f2a944c

Please sign in to comment.