docs.unity3d.com
Search Results for

    Show / Hide Table of Contents

    On Destroy

    The On Destroy event node is triggered when the object containing the script is destroyed.

    Things you won't be able to do after an On Destroy:

    • Get data from components within the destroyed object.
    • Add Timed nodes such as Wait, Stop Watch as the script component will be destroyed when they process.
    • On Update event won't process after.

    Ports

    Inputs

    Port Name Type Default Value Description
    [Boolean] True If Enabled is set to true (Checked), the On Destroy event will be triggered when the object containing the script is destroyed.

    Outputs

    Port Name Type Default Value Description
    Trigger Execute next action after the GameObject is destroyed.

    Examples

    In this example, we have a Cube containing a visual script that will:

    1. Trigger the On Start event when entering play mode

      1. Wait 2 seconds.
      2. Destroy the game object Cube.
    2. When the Cube get destroyed, the On Destroy event will be triggered.

      1. The message Destroyed will now be written in the console.
    In This Article
    Back to top
    Copyright © 2024 Unity Technologies — Trademarks and terms of use
    • Legal
    • Privacy Policy
    • Cookie Policy
    • Do Not Sell or Share My Personal Information
    • Your Privacy Choices (Cookie Settings)