Entity Graphs
The Entity Graph implements a visual scripting language based on nodes and connections. To use it, right-click on an entity to add a Graph Component and then double click on the Graph Component to open it in the Graph Editor:
Basic Concepts
How to use the Entity Graph?
You need to add a Graph Component to an Entity of your choice.
After that, you have two ways of opening the Graph:
-
Double Click the Graph Component
-
Click in the Property View on Edit
Now the Graph Editor Opens and you can start adding nodes via:
- Right Click -> Add Node
- Press Space
Execution
The Entity Graph is an event-driven Visual Scripting language. This means everything happens after an event is triggered! By default, the Engine comes with the following built-in Events:
Name | Description | |
---|---|---|
Init Event | Is called when the component is added to the Entity. | ![]() |
Reload Event | Is called when the component is reloaded from the truth. | ![]() |
Tick Event | Is called every frame. | ![]() |
Terminate Event | Is called before the component is removed from the entity. | ![]() |
Custom Event | Is called when the named event is triggered with either a "Trigger Event" node or from the outside with "Trigger Remote Event" | ![]() |
Trigger Event | Triggers an event. | ![]() |
Trigger Remote Event | Triggeres an event on a remote Entity | ![]() |
UI Tick | Is ticked every frame regardless if the game is paused or not! | ![]() |
Anatomy
There are six types of nodes:
Type | Function |
---|---|
Event Node | Starting point of the Execution |
Query Node | Query nodes are triggered automatically when their output is requested. Nodes that aren't query nodes need to be triggered. Therefore they are "Pure" and do not modify data! |
Nodes | Normal nodes that have an Event input, hence they might modify the data and produce an output or mutate the graphs state! |
Subgraphs | Graphs within a Graph! Allow you to organize your graph into smaller units. They can also be reused if saved as Subgraph Prototype. |
Input Node | Accepts Input from the Outside world and makes it available to the graph. Mainly used for communication between graphs and subgraphs. |
Output Node | Accepts Output and passes it to the Outside world and makes it available to a parent graph. Mainly used for communication between graphs and subgraphs. |
Moreover, the Visual Scripting language knows two different types of wires:
- Event Wires They regulate the execution flow.
- Data Wires Transport the data from node to node!
Inputs
Graphs can have inputs. They can be used to allow the user of your graph to pass data from the outside (e.g. the Editor) to the graph. This happens via the Input Nodes. In the General Graph settings you can add Inputs from the outside world.
Adding a Public Input
- You click on the Settings button which opens the Graphs Settings
-
You expand the Input Accordion and press "Add"
-
This will add a new Input to your graph! There you have a few options.
To make your node public just check the publicly accessible from another graph or from the Editor check the Public checkbox
If you now select the Graph Component of your Entity you will be able to change the value:
This can be a nice way to customize behaviour of your graph and entity!
-
Add an Input node to your graph. There you have access to the data.
The Input Node also allows you to access the settings. Hover over the name of the Input and a Settings option becomes available.
Variables
You can store data within your Graph! The Set / Get Variable nodes are the way to go. They give you access to this function. You can also access variables from distance Entities by using the Set / Get Remote Variable nodes.
Branches and loops
The Language comes with built-in support for branches, the If node. The Language supports multiple bool operators to compare values.
Besides, you have two nodes for loops:
- The Grid node
- The For node
The Grid node for example:
Subgraphs
You can organize your code into smaller reusable units and combine nodes as a subgraph! Using subgraphs makes your Graph more user-friendly, and it will look less like spaghetti. You can store your subgraph as a .entity_graph
asset in your asset browser and allow it to be reused across your project! Which enables you to have maximal flexibility!
What is next?
In the next chapter you will learn more about Subgraphs and the Debugger! In case you want to provide your own Nodes check out this tutorial Extend the Entity Graph