If you are totally new, check out our post on Unity instantiate to understand more details. In this tutorial, we will instantiate a player object on to the scene using visual scripting.
I will be using Unity 2021.1.13 for this tutorial
Creating a flow graph
- Create a new empty object in the hierarchy window.
- Name it as instantiate_graph.
- Go to inspector window and click add component.
- Add a Script machine component.
- Click new to create a new graph.
- Name it as instantiate_example.
Creating the logic
We are going to instantiate a prefab called my_prefab after 5 seconds of game start.
- Add a timer unit, get rotation and an instantiate gameobject node.
- set the timer duration to 5 seconds.
- Connect start event to timer start, time completed to instantiate.
- Set the game object to my_prefab in the instantiate node.
- Get the rotation of this gameobject using get rotation node and connect it as input to the instantiate node.
- You can change the position where you want the prefab to be instantiated in the instantiate node.