Script doesn't carry out commands before being destroyed

So I have a statement in which a player collides with a trigger, it does an action. It’s meant to do everything and then at the end destroy itself. But it won’t work as it will just skip everything and just go to Destroy(gameObject);.

My default Idea was

    void OnTriggerExit2D(Collider2D col)
    {
        if (col.gameObject.tag == "KillZone")
        {
            Debug.Log("Test");
            TestBool = true;
            TestInt += 2;
            //KillPlayer();

            Destroy(gameObject);
        }
}

    void KillPlayer()
    {
        Debug.Log("Test Void");

        Destroy(gameObject);
    }

And what it does is it just skips to Destroy(gameObject) not doing anything else. Once in a while it will run the debug.log but not consistanly. I even tried making it call KillPlayer with destroy disabled within the OnTriggerExit but it won’t call it.

Is there something about how mayb ontriggerexit works that it only calls the most important one something else?

Does anyone know why it might not want to do anything else such as setting a bool to true or calling KillPlayer? Thanks

Your code certainly runs, the question is “does the destruction cancels Debug instructions”. Which is possible, there’s a lot of work behind the scene of Debug.Log.

The easiest way to solve this is to add a delay to the destroy, and test again. Use Destroy(gameobject, 0.1f);