This commit is contained in:
Sebastien Lebreton 2024-05-24 08:11:26 +02:00 коммит произвёл GitHub
Родитель fcaa655a81
Коммит f2a944c6cc
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
1 изменённых файлов: 2 добавлений и 2 удалений

Просмотреть файл

@ -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.
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.