How to destroy an object using visual scripting in Unity

In our recent tutorial on how to destroy game object, we had used code to destroy the game object. In this tutorial, we will be using visual scripting to do the same.

I will be using Unity 2021.1.13 for this tutorial.

Creating a flow graph

  1. Click on the object you want to destroy and go to the inspector window.
  2. Click on Add component and add Script Machine.
  3. Create new flow graph by clicking new in the script machine.
  4. Give it a name and save it.

Creating the logic

We are going to destroy the game object after 5 second’s delay

  1. Click edit on the script machine component.
  2. Add a timer block, this block and a destroy block.
  3. Set the timer duration to 5 seconds.
  4. Connect the output of this block to the obj input of the destroy block.
  5. Connect start event to timer start and timer completed to destroy gameobject block.
  6. Here is How the final graph looks like.
visual scripting flow graph to destroy game object in unity

Free Unity asset banner

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.