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
- Click on the object you want to destroy and go to the inspector window.
- Click on Add component and add Script Machine.
- Create new flow graph by clicking new in the script machine.
- Give it a name and save it.
Creating the logic
We are going to destroy the game object after 5 second’s delay
- Click edit on the script machine component.
- Add a timer block, this block and a destroy block.
- Set the timer duration to 5 seconds.
- Connect the output of this block to the obj input of the destroy block.
- Connect start event to timer start and timer completed to destroy gameobject block.
- Here is How the final graph looks like.