﻿# V3211\. Unity Engine\. The operators '?\.', '??' and '??\=' do not correctly handle destroyed objects derived from 'UnityEngine\.Object'\.

The analyzer has detected a potential error related to the object derived from UnityEngine\.Object\. This object was used with the null\-conditional \(?\.\) or null\-coalescing \(?? and ??\= \) operator\.

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 the `?.`, `??`, and `??=` operators\. They cannot be overloaded, so they do 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?.isJammed())
    {....}
  }
}
```

When addressing `bullet`, the check with a null\-conditional operator \(`?.` \) will not consider that the object may be destroyed, since this operator cannot be overloaded\.

To fix this, it is recommended to 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 ? bullet.isJammed() : null)
    {....}
  }
}
```