Search code examples
c#unity-game-enginecode-generationunity3d-editor

How does a Unity3d visual scripting framework work behind the scene?


I'd like to know what happens when I use a visual scripting tool in unity3d.

Let's say I want to make an FSM:

The first approach is when I don't use such a tool. In this case, I should do everything inside the source code(C#), meaning creating all the necessary classes and wiring up the whole state machine manually.

The second approach is when I use a tool like Bolt or NodeCanvas. I still need to write the State classes, but this time, wiring them up is done visually through a node-based graph editor.

The question is, how these tools convert that graph into something that Unity can use? Do they generate C# code based on the graph using a templating engine like T4 Templating Engine? Or do they do something else?


Solution

  • They can either generate some C# code or save the graph definitions to a file, add a runtime execution engine to your game and interpret those while the game is running. They might also take a hybrid approach or do some performance optimizations. So either way is possible and you should consult the tools' design docs to make sure.

    As for Bolt, this post on the developer's official blog, implies that current stable version doesn't generate any C# code. But apparently the team is actively working on a new version that supports code generation.

    We are currently actively working on Bolt 2, a major new version that includes massive overhauls and new features such as C# generation, classes, vertical flow, tweening, generics, a fresh new look, and a lot more.

    As for NodeCanvas, I'm not sure if it's generating any C# code, but judging by the package contents on the assets store, looks like it's working in a similar way to Bolt.