Navigation
API > API/Plugins > API/Plugins/GameplayGraph
A UGraph is a collection of nodes and edges. This graph representation is meant to be easily integrable into gameplay systems in the Unreal Engine.
Conceptually, you can imagine that a graph is meant to easily represent relationships so we can answer queries such as:
- Are these two nodes connected to each other?
- How far away are these two nodes?
- Who is the closest node that has XYZ?
- etc.
UGraph provides an interface to be able to run such queries. However, ultimately what makes the graph useful is not only the relationships represented by the edges, but also the data that is stored on each node and each edge. Depending on what the user wants to represent, the user will have to subclass UGraphVertex and UGraphEdge to hold that data.
As the user adds nodes and edges into the graph, they will also be implicitly creating "islands" (i.e. a connected component in the graph). Each graph may have multiple islands. Users of the graph can disable the island detection/creation if needed.
Note that this is an UNDIRECTED GRAPH.
| Name | UGraph |
| Type | class |
| Header File | /Engine/Plugins/Experimental/GameplayGraph/Source/GameplayGraph/Public/Graph/Graph.h |
| Include Path | #include "Graph/Graph.h" |
Syntax
UCLASS (MinimalAPI)
class UGraph : public UObject
Inheritance Hierarchy
- UObjectBase → UObjectBaseUtility → UObject → UGraph
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
UGraph() |
Graph/Graph.h |
Variables
Public
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| OnEdgeCreated | FOnGraphEdgeCreated | Graph/Graph.h | ||
| OnEdgeRemoved | FOnGraphEdgeRemoved | Graph/Graph.h | ||
| OnIslandCreated | FOnGraphIslandCreated | Graph/Graph.h | ||
| OnVertexCreated | FOnGraphVertexCreated | Graph/Graph.h |
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| Islands | TMap< FGraphIslandHandle, TObjectPtr< UGraphIsland > > | Graph/Graph.h | ||
| Properties | FGraphProperties | Graph/Graph.h | ||
| Vertices | TMap< FGraphVertexHandle, TObjectPtr< UGraphVertex > > | Graph/Graph.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
void ChangeVertexHandle
(
const FGraphVertexHandle& OldVertexHandle, |
Changes a node handle, updating all the references. The vertex must exist. | Graph/Graph.h | |
void CreateBulkEdges
(
TArray< FEdgeSpecifier >&& NodesToConnect |
Creates edges in bulk. | Graph/Graph.h | |
FGraphVertexHandle CreateVertex
(
FGraphUniqueIndex InUniqueIndex |
Create a node with the specified subclass, adds it to the graph, and returns a handle to it. | Graph/Graph.h | |
void Empty() |
Graph/Graph.h | ||
virtual void FinalizeVertex
(
const FGraphVertexHandle& InHandle |
This should be called immediately after a node and any relevant edges have been added to the graph. | Graph/Graph.h | |
void ForEachIsland
(
TLambda&& Lambda |
Graph/Graph.h | ||
FGraphVertexHandle GetCompleteNodeHandle
(
const FGraphVertexHandle& InHandle |
Given a node handle, find the handle in the current graph with a proper element set. | Graph/Graph.h | |
const TMap< FGraphIslandHandle, TObjectPtr< UGraphIsland > > & GetIslands() |
Graph/Graph.h | ||
const FGraphProperties & GetProperties() |
Graph/Graph.h | ||
UGraphIsland * GetSafeIslandFromHandle
(
const FGraphIslandHandle& Handle |
Graph/Graph.h | ||
UGraphVertex * GetSafeVertexFromHandle
(
const FGraphVertexHandle& Handle |
Graph/Graph.h | ||
const TMap< FGraphVertexHandle, TObjectPtr< UGraphVertex > > & GetVertices() |
Graph/Graph.h | ||
void InitializeFromProperties
(
const FGraphProperties& Properties |
Graph/Graph.h | ||
int32 NumIslands() |
Graph/Graph.h | ||
int32 NumVertices() |
Graph/Graph.h | ||
void RefreshIslandConnectivity
(
const FGraphIslandHandle& IslandHandle |
Refresh the connectivity of the given island (re-check to see whether it should be split). | Graph/Graph.h | |
void RemoveBulkVertices
(
const TArray< FGraphVertexHandle >& InHandles |
Graph/Graph.h | ||
void RemoveEdge
(
const FGraphVertexHandle& VertexHandleA, |
Removes an edge between two nodes | Graph/Graph.h | |
void RemoveIsland
(
const FGraphIslandHandle& IslandHandle |
Remove an island from the graph. | Graph/Graph.h | |
void RemoveVertex
(
const FGraphVertexHandle& NodeHandle |
Removes a node from the graph along with any edges that contain it. | Graph/Graph.h |
Protected
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
void MergeOrCreateIslands
(
const TArray< FEdgeSpecifier >& InEdges |
When we add multiple edges into the graph. | Graph/Graph.h | |
void RemoveOrSplitIsland
(
TObjectPtr< UGraphIsland > Island |
After a change, this function will remove the island if it's empty or will attempt to split it into two smaller islands. | Graph/Graph.h | |
void ReserveIslands
(
int32 Delta |
Graph/Graph.h | ||
void ReserveVertices
(
int32 Delta |
Used for bulk loading in vertices/edges/islands. | Graph/Graph.h |