How check gameobject destroy?

I try to assign the gameobject to a variable, and check if the variable become null after the gameobject destroy.

It seems to work, but when i look at the inspector when running. The variable become “missing transform” very late after the gameobject destroyed. It seems to be 2 to 3 sec delayed.

Remember that Destroy() doesn’t immediately destroy a GameObject, rather marks it for deletion at the end of the frame. Could you post the code that you’re having trouble with?

The bullet script:

void Awake()
    {

        Destroy(gameObject, 4);
  
}


    void OnCollisionEnter(Collision collision)
    {

        enlarge = true;

        GameObject.Destroy(transform.GetComponent<Rigidbody>());

        transform.Find("Explosion00").gameObject.SetActive(true);
        transform.Find("Explosion01").gameObject.SetActive(true);


        if (collision.transform.GetComponent<RobotAI>())
        {
            collision.transform.GetComponent<RobotAI>().weaponEffectByHit = true;
            collision.transform.GetComponent<RobotAI>().weaponEffect = transform.Find("Explosion00");
        }
  
  
}

This is the script of object I keep looking at in Editor inspector:

        void FixedUpdate()
    {

        // Stop moving and start defend animation
        if (defendMode == true)
        {

            // Defend Idle animation finish, resume other animation
            if ( weaponEffect==null && weaponEffectByHit)
            {
                animator.SetTrigger("Defend Idle End");
                defendMode = false;
                weaponEffectByHit = false;
            }
      

        }

i find weaponEffet become “missing” very late after the bullet disappear on the scene.

You should add a Debug.Log to check if it’s null. Maybe the inspector just doesn’t update very quickly, although it should.

if (variable == null) Debug.Log("It's null");

The inspector only updates when it gets an update message. That happens kinda whenever Unity feels like it. I think one of the things that should be triggering it is a value changing, but it might be that a value getting destroyed does not count.

Try (literally) waving your mouse over the inspector as the object gets destroyed.