From f2a944c6cc85a3cdcc200622cfcdb432a99310d7 Mon Sep 17 00:00:00 2001 From: Sebastien Lebreton Date: Fri, 24 May 2024 08:11:26 +0200 Subject: [PATCH] Update USP0022.md --- doc/USP0022.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/USP0022.md b/doc/USP0022.md index 35d08cd..09ddef0 100644 --- a/doc/USP0022.md +++ b/doc/USP0022.md @@ -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. @@ -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. \ No newline at end of file +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.