
Creating a flowgraph
Now that we have a basic understanding of how the Flowgraph Editor works, let's dive right in and create our first flowgraph! You can close the Flowgraph Editor for the moment.
The flowgraph entity
The flowgraph entity is an extremely lightweight CryENGINE object, designed to be used when you need a flowgraph that isn't applied to any specific entity. Like all entities, it can be found in RollupBar inside Sandbox.
Note
If you're not sure what an entity is, skip this section until you have read Chapter 3, Creating and Utilizing Custom Entities.

Select FlowgraphEntity and then either double-click and click again on the viewport, or click and drag it into the level. You should now see a whole new set of options in RollupBar, including entity params, material layers, but mostly important for us, the Entity: FlowgraphEntity section.
Attaching a new flowgraph
Inside the Entity: FlowgraphEntity section, we need to find the Flow Graph subsection, and then click on the Create button:

From here, you'll be presented with the option to assign your flowgraph to a group. Whether you do or not isn't really important for now, but it's useful for grouping related graphs together, particularly when working on larger projects.
Once this is done, you should see the Flowgraph Editor appear with a faint grid overlaid on the background. We're now ready to start creating logic!
Adding nodes into flowgraphs
The simplest method of adding a node into a new graph is to browse through the Components list and drag new nodes in. However, this isn't very efficient if you know the name of the node you want to add. Therefore, you can also use the Q shortcut key inside the Flowgraph Editor to bring up the search function, and just type in the name of the node you'd like to add.
In our case, we're going to begin with the Misc:Start node, which is a simple node used to set off other events when the level is loaded, or when an Editor test session is started:

Input and output ports
Once the node is placed, you should see your first example of a node's input and output ports. In this case, we have two input values, InGame and InEditor, as well as a single output port, conveniently named output in this case:

Input ports are used to feed data into the node, or trigger events, and output ports are used to relay data and events to other nodes in the graph. In this example, the Misc:Start node can be edited to define in which game contexts it will actually be executed. Perhaps you have some debugging logic you'd like to only run in the Editor, in which case we could set InGame to false, or zero.
In order to specify what type of data a port will handle, we need to know its port type. We can tell which type a port is in the Flowgraph Editor by looking at its color.
Following is a list of the available port types:
- Void: This is used for ports that don't pass a specific value, but are activated to signal an event
- Int: This is used when the port should only receive integer values
- Float: This is used to indicate that the port handles floating point values
- EntityId: This indicates that the port expects an entity identifier. (Refer to Chapter 3, Creating and Utilizing Custom Entities for more information on entity IDs)
- Vec3: This is used for ports that handle three-dimensional vectors
- String: In this, the port expects a string
- Bool: This is used when the port expects a Boolean value of true or false
Target entities
Flownodes can feature a target entity, allowing the user to link an entity from the current level to the flownode. This is useful for nodes that are meant to impact entities in the game world, for example the Entity:GetPos node, as shown in the following screenshot, gets the world transformation of the specified entity.

There are two ways of assigning an entity to a node that supports it:
- By linking another flownodes' EntityId output to the Choose Entity input
- By right-clicking on the Choose Entity input and selecting:
- Assign selected entity: This links the node to the entity currently selected in the Editor viewport
- Assign graph entity: This links the node to the entity this graph is assigned to
Linking flownodes
A single flownode isn't capable of much; let's connect two, and build a proper graph! For demonstration purposes, we'll use the Time:TimeOfDay node:

To create a link between ports as shown in the previous screenshot, simply click on an output port and drag your cursor to an input port with the mouse button held down. Release the mouse, and the connection should be created!
We've also edited the value of the Time input port; input ports can either be fed data via output ports, or have their values edited directly in the Editor. To do this, just click on the node and see the Inputs section of the Flowgraph Editor. From there, you can simply edit the values:

You can also see valuable information about the node: for example, here we can see that this node is used to set the time of day, and the speed at which time passes in game.
With this done, you can close the Flowgraph Editor for now. Flowgraphs don't have to be saved manually; they're automatically saved with the level.
Testing our flowgraph
As we learned in the previous chapter, testing logic in the CryENGINE is incredibly simple using Sandbox. Simply press the Ctrl + G shortcut key combination, and watch as you enter game mode. Now, when you do this, you should see the lighting and general atmosphere of the level changing,as you've just changed the time of day!
Congratulations, you've just taken your first step to creating games using CryENGINE! It doesn't seem like much right now, but let's make this graph do a bit more.