?. or ?? is used on a Unity object, which skips Unity's own check for destroyed objects
What it finds
Unity objects that were destroyed compare equal to null through an overloaded ==, but ?. and ?? test the reference directly and see the destroyed object as alive; the next access then throws. An explicit == null test, or an implicit bool test, uses Unity's check. The rule reports ?. and ?? on GetComponent results and on variables declared with common Unity object types, in files that use UnityEngine.
From the rule's source, unity_object_null_propagation.rs.
using UnityEngine; class Shooter : MonoBehaviour{ private Rigidbody body; void Fire() { body?.AddForce(Vector3.up);tx0 reports: ?. skips Unity's check for destroyed objects if (body != null) { body.AddForce(Vector3.up); } }} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/csharp:unity-object-null-propagation" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/csharp:unity-object-null-propagation] reason="..."tx0 explain tx0/csharp:unity-object-null-propagation shows the same in the terminal. Found a false positive? Report it.