The new Monaverse Developer Kit includes the ability to create custom experiences using Visual Scripting.
Visual scripting is a method of creating game logic using a visual interface instead of writing code in another programming language. This makes it easier for creators to make incredible experiences, all inside Unity 3d.
Visual Scripting is available in all Mona spaces using the Unity 2022 Mona SDK.
- You may need to import the Visual Scripting asset from the Package Manager. Go to 'Window/Package Manager' and select 'Packages : Unity Registry' at the top.
- Scroll down to 'Visual Scripting', then select 'Install' at the top right of the window.
Visual Scripting is done as a component on an asset. For the purposes of this tutorial, we will add a graph to a simple cube, but of course you can add it to anything you want.
- With the asset selected, select 'Add Component' in the Inspector.
- Type in 'Script machine' (or enough to pull that up or scroll down to the 'Visual Scripting' menu and select 'Script Machine'.
- The source defines where the graph is found.
- Embed adds the script to the asset itself. You can add a Title and a Summary if you wish.
- The other source option is Graph.
- Graph creates an external graph file that you could use on other assets.
- If you select Graph, select 'New' to save your new visual script graph to your assets. The Title and the Summary are available in the graph itself.
- At the base you have 'Edit Graph' which is where you start creating your nodes.
The Node Graph is where all the magic happens. Think of it much like a story going from left to right where each node happens over time.
There are two base nodes, On Start and On Update :
- 'On Start' happens once at the very beginning of the assets 'life'. Anything that you need to setup for the asset initially stems from here.
- 'On Update' happens every time the frame is updated, so these nodes will be played out all the time.
The Visual Scripting Node Graph
- There are two ways to add a node :
- Right click on the graph and then search for the node you are after
- Drag an arrow from a node, once you let go you can search for the node you are after.
- If you create nodes without using the connection you can connect nodes simply by dragging from the arrows to the left and right of nodes.
- It is possible to delete connections by right clicking on the arrows on the left/right of the node.
- You can create Groups easily by holding Ctrl and left drag to create a Group node. If this surrounds multiple nodes, you can move them all easily.
- You can rename the group by clicking the label once.
- Delete the group by selecting it and pressing 'Delete', or right click and select 'Delete'.