Visual Scripting

Runtime Visual Scripting for Unity

This is a particularly hard one. Visual scripting is, as the name suggest, a graphical way to program. I want to achieve this in Unity in runtime, which means that new logic can be created while the game is running. So the program does not have to be recompiled as the user create new content.

This poses a problem, at runtime, we can’t compile new C# code, so the user can’t use C# to customize the blocks used in the visual scripting.

The solution is using the Lua interpreter (another scripting language) that is implemented within C# called MoonSharp ( So if custom blocks are needed the user can create them using Lua, otherwise the user can freely connect blocks to each other to create logic without coding.

In the beginning of the video, I show the visual scripting in action, every block is executed sequentially. Then, I went to the source code to show that the logic for each block is coded in LUA using the interpreter. This means that new blocks can be created in runtime, no need to recompile the whole program.

At the end of the video, I show that the visual scripting tool creates blocks that can be serialized to json. So I load the json text, and the visual scripting blocks and connections are loaded. Evidently, this is an active development.


Tags: No tags

Leave a Comment