Logic graphs

You can give objects behaviour without writing code. Connect nodes in a Blender node editor: an event starts a chain of actions, and values plug into them. When you press Play, the graph becomes Lua and runs like any other script.

A logic graph in Blender's node editor: On Update rotates the coin; On Trigger Enter checks it's the player, adds to the coins variable, updates the HUD, plays a sound and destroys the coin

1. Start a graph

  1. Select an object, then go to BlendForge tab → Object Components → Script and click the new-file button next to Logic. For the whole level, use World → Level Logic.
  2. Open a node editor, for example by changing the Timeline at the bottom, and choose BlendForge Logic from its editor-type menu. The new graph opens with an On Start node already wired to a Print node.
  3. Press Shift+A to add nodes, drag from a socket to connect it, and press Play.

The node editor’s sidebar (N → BlendForge) says whether the graph compiles, and Show as Lua puts the code it becomes in a Text.

2. How graphs run

Unconnected inputs use what you type into them. An object input left unconnected means this object; in the level’s graph it means the player.

The nodes

EventsOn Start, On Update (with Delta Time), On Trigger Enter / Exit (with Other), On Interact (with Player, and a Prompt), On Key Pressed, Every N Seconds, On Custom Event (with Value)
FlowBranch, Delay, Do Once, For Each Object (every object whose name starts with…)
ActionsPrint, Show Message, Set HUD Text, Move, Rotate, Set Position, Set Rotation, Set Visible, Look At, Push, Destroy, Spawn, Play Sound, Play Object’s Sound, Play Animation, Emit Particles, Walk To (AI agents), Send Event, Set Variable, Add to Variable, Load Level, Restart Level, Respawn Player, Set Checkpoint
ValuesSelf, Player, Find Object, Get Variable, Object Property (a custom property from Blender), Position, Distance, Number, Vector, Separate XYZ, Join Text, Math, Vector Math, Compare, And / Or / Not, Is Player, Key Down, Random, Time

Values and variables

Set Variable, Add to Variable and Get Variable have a Scope. A Game variable is shared by every script and graph (it’s Lua’s game table) and carries over to the next level. An Object variable belongs to that one object; give a door its own open variable, for example. A number joined to text with Join Text is written without “.0”, so you get “Coins: 3”.

Custom events

Objects talk to each other with events. A lever’s Send Event named open, sent to the door (Find Object “Door”), runs the door’s On Custom Event named open. Lua can send the same event with find("Door"):call("open").

Graphs and Lua together

The demo

In the Samples & docs download, samples\make_logic_demo.py builds a level made only of graphs: three spinning coins sharing one graph and counted on the HUD, a lever whose Send Event opens a sliding door, a ball dropper (F), and a level graph that notices when every coin is collected. Open samples\logic_demo.blend and pick each graph in the node editor’s browse menu.