Navigation
API > API/Plugins > API/Plugins/DisplayCluster
Distributed custom state
This state enables data exchange in any direction within a cluster. By default, any cluster node can access the values of any other node. An additional API is provided to customize data propagation paths in arbitrary ways.
GetData() and GetData(NodeId) are thread-sensitive. The data is maintained in separate copies for the game and render threads. Access from other threads is not supported.
Distributed states are automatically registered for replication during creation (see the Create() call in the examples below). Once registered, replication within the cluster begins immediately. To stop replication, the state must be explicitly unregistered.
This state type has no leader or explicit data source; it is a generic mechanism for data exchange. Data propagation is performed synchronously to preserve determinism, which may introduce update latency.
When the state is modified on the game thread, the expected latency is one frame: a value set on frame N becomes visible via GetData() on frame N + 1. If the value is updated before state synchronization, no latency is introduced.
When modified on the render thread, the latency may be 2–3 frames, as the value is first propagated to the game thread and then passed back to the render thread.
This class uses internal data serialization. Any custom TDataType must provide its own serialization functions. Refer to the examples below for details. +---------------------+ +---------------------+ ¦ NodeA::Value=5 ¦ ¦ NodeB::Value=2 ¦ +---------------------¦ +---------------------¦ +- ¦ NodeA: Value=5, R/W ¦ ----> ¦ NodeA: Value=5, R/O ¦ ¦ ¦ NodeB: Value=2, R/O ¦ <- ¦ NodeB: Value=2, R/W ¦ -+ ¦ +-> ¦ NodeC: Value=8, R/O ¦ ¦ NodeC: Value=8, R/O ¦ <-+ ¦ ¦ ¦ +------------------+ +------------------+ ¦ ¦ ¦ ¦ ¦ ¦ ¦ ¦ +------------------+ ¦ ¦ ¦ ¦ ¦ NodeC::Value=8 ¦ ¦ ¦ ¦ ¦ +------------------¦ ¦ ¦ +-+----------------> ¦ NodeA: Value=5, R/O ¦ ¦ ¦ ¦ ¦ NodeB: Value=2, R/O ¦ <-------------+-+ +-------------- ¦ NodeC: Value=8, R/W ¦ --------------+ +------------------+EXAMPLE - Base type
using FMyState = TDistributedCustomState
const FName MyStateName = TEXT("MyStateFloat"); // The name must be unique TSharedPtr
MyState->SetData(0.75f); // Set new value MyState->SetData(0.85f); // It can be called multiple times, the last one will be used on the next frame
const TSet
IDisplayCluster::Get().GetClusterMgr()->UnregisterCustomState(MyStateName); // Unregister it from replication on this cluster node IDisplayCluster::Get().GetClusterMgr()->RegisterCustomState(MyStateName, MyState); // Register again
MyState->SetCustomUpstreamsEnabled(true); // Enable custom upstream configuration MyState->SetUpstreams({ TEXT("Node_0"), TEXT("Node_1") }); // Receive updates from Node_0 and Node_1 onlyEXAMPLE - Custom type
// Any custom types struct FMyStruct { int32 Items = 0; float Progress = 0.f; bool bIsActive = false; };
// With custom serialization inline FArchive& operator<<(FArchive& Ar, FMyStruct& MyStruct) { Ar << MyStruct.Items; Ar << MyStruct.Progress; Ar << MyStruct.bIsActive; return Ar; }
using FMyState = TDistributedCustomState
const FName MyStateName = TEXT("MyStateStruct"); // The name must be unique TSharedPtr
MyState->SetData({ 2, 0.3f, true }); // Set new value MyState->SetData({ 9, 0.5f, true }); // It can be called multiple times, the last one will be used on the next frame
const TSet
FMyStruct CurrentFrameState = MyState->GetData(); // Get data on current frame (game/render thread sensitive) CurrentFrameState = { 10, 1.f, false }; MyState->SetData(MoveTemp(CurrentFrameState)); // Move semantics can be useful for complex types
| Name | TDistributedCustomState |
| Type | class |
| Header File | /Engine/Plugins/Runtime/nDisplay/Source/DisplayCluster/Public/Cluster/CustomStates/DisplayClusterCustomStateDistributed.h |
| Include Path | #include "Cluster/CustomStates/DisplayClusterCustomStateDistributed.h" |
Syntax
template<typename TDataType>
class TDistributedCustomState :
public UE::nDisplay::Private::TCustomStateData< TDataType > ,
public UE::nDisplay::Private::TCustomStateFactory< TDistributedCustomState< TDataType > >
Inheritance Hierarchy
- TCustomStateFactory → TDistributedCustomState
Implements Interfaces
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Private constructor. Only factory method can instantiate this class. | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual ~TDistributedCustomState() |
Cluster/CustomStates/DisplayClusterCustomStateDistributed.h |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| ThisType | TDistributedCustomState< TDataType > | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h |
Variables
Protected
| Name | Type | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|---|
| bUseCustomUpstreamConfiguration | bool | Whether custom upstream configuration is enabled | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h | |
| UpstreamNodes | TSet< FName > | Custom upstream cluster node IDs | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h |
Functions
Public
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
TSet< FName > GetAvailableNodes() |
Returns node IDs available in the storage | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h | |
const TDataType & GetData
(
const FName& NodeId |
Returns state data of a specific node. The data is bound to current thread and frame. | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h | |
void SetCustomUpstreamsEnabled
(
bool bEnabled |
Enable/disable custom upstream configuration | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h | |
void SetUpstreams
(
const TSet< FName >& NewUpstreamNodes |
Configure upstream nodes that should propagate their updates to this state instance | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h |
Public Virtual
Overridden from IDisplayClusterCustomState
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual void AdvanceFrame() |
Progress to the next frame | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h | |
| Returns type identificator | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h | ||
virtual TSet< FName > GetUpstreams () |
Returns set of node IDs that this custom state is expecting to get updates from. | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h | |
virtual bool HasCustomUpstreamConfiguration () |
Whether this state requires some custom update path. | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h | |
virtual void Serialize
(
FArchive& Ar |
SerializationIt's used to serialize data of a custom state into an output buffer | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h | |
| Deserialization | Cluster/CustomStates/DisplayClusterCustomStateDistributed.h |