Destroyed gameobject found with FindObjectsOfType<>?

I’m making a simple level editor for a 2D platformer. When I delete (Destroy()) a tile in the level editor, then try to recalculate the textures for my tile stitching, the remaining tiles behave as if the destroyed tile were still in the scene.

//Delete the (topmost) object at the mouse position
    void DeleteObject() {
        Collider2D hit = Physics2D.OverlapCircle(Camera.main.ScreenToWorldPoint(Input.mousePosition), 0.0001f, menuMask);

        if (hit != null) {
            if (hit.gameObject.GetComponent<Tile>() != null) {
                Destroy(hit.gameObject);
                Recalculate();
            }
        }
    }

    void Recalculate() {
        Tile[] tiles = FindObjectsOfType<Tile>();
        foreach (Tile t in tiles) {
            t.RecalculateTexture();
        }
    }

In the above code, “hit.gameObject” is included in the array “tiles” after being destroyed, and the other tiles in “tiles” don’t re-stitch themselves properly as a result. What do I need to do differently to destroy the hit tile completely before Recalculate() is called?

When you call Destroy a GameObject, Unity will wait until the end of the frame (or cycle I can’t remember which but lets say frame to be safe) before it removes that object from the scene and releases its memory. If you ask Unity for a component from that GameObject before the end of the frame that you called Destroy on it, Unity will save that component and not release its memory while at the same time destroying all other parts of said GameObject. If you want to Recalculate() right after the destroy use a Coroutine to break the two commands apart by a frame:

    //Delete the (topmost) object at the mouse position
    void DeleteObject()
    {
        Collider2D hit = Physics2D.OverlapCircle(Camera.main.ScreenToWorldPoint(Input.mousePosition), 0.0001f, menuMask);

        if (hit != null && hit.gameObject.GetComponent<Tile>() != null)
        {
            StartCoroutine(destroyThenRecalculate(hit.gameObject));
        }
    }

    void Recalculate()
    {
        Tile[] tiles = FindObjectsOfType<Tile>();
        foreach (Tile t in tiles)
        {
            t.RecalculateTexture();
        }
    }

    IEnumerator destroyThenRecalculate(GameObject hitObj)
    {
        Destroy(hitObj);
        yield return null;
        Recalculate();
    }