﻿# V3212\. Unity Engine\. Pattern matching does not correctly handle destroyed objects derived from 'UnityEngine\.Object'\.

The analyzer has detected a potential error related to the object derived from UnityEngine\.Object\. The object was used with pattern matching to check for null\.

According to the [Unity documentation](https://docs.unity3d.com/6000.0/Documentation/ScriptReference/Object.html#:~:text=null-conditional%20operator%20(%3F.)%20and%20the%20null-coalescing%20operator%20(%3F%3F)%20are), it is not recommended to use pattern matching with objects derived from `UnityEngine.Object`\. 

The check for `null` using pattern matching does not consider that objects derived from `UnityEngine.Object` may be destroyed\. Therefore, the check may have an incorrect result\.

Look at the example:

```cpp
class CustomComponent: MonoBehaviour
{
  public bool HitConfirm(....)
  {  
    Projectile bullet;
    ....
    if(....)
      Destroy(bullet);

    if (bullet is not null) 
    {....}
  }
}
```

In this case, the check of `bullet` using pattern matching will not consider that the object may be destroyed\.

To fix this, use a check with the `==` or `!=` operator\.

The fixed code:

```cpp
class CustomComponent: MonoBehaviour
{
  public bool HitConfirm(....)
  {  
    Projectile bullet;
    ....
    if(....)
      Destroy(bullet);

    if (bullet != null) 
    {....}
  }
}
```