Navigation
API > API/Plugins > API/Plugins/DisplayCluster
Shared custom state.
"Shared" means there is a single source of truth. This implementation always propagates the state data from the primary node to all other nodes. Regardless of which node GetData() is called on, the returned data will always match the primary node's value. Consequently, SetData() is ignored on all non-primary nodes.
GetData() is thread-sensitive. The state maintains separate copies for the game and render threads. Access from other threads is not supported.
Shared 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.
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 updated on the render thread, latency may be 2–3 frames, as the value is first propagated to the game thread and then 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.
+-------------+ +-----------------+ ¦ Primary node ¦ ¦ Secondary node ¦ +-------------¦ Replication +-----------------¦ ¦ Value=5, R/W ¦ ---------------> ¦ Value=5, Read only ¦ +-------------+ ¦ +-----------------+ ¦ ¦ ¦ +-----------------+ ¦ ¦ Secondary node ¦ ¦ +-----------------¦ +---> ¦ Value=5, Read only ¦ +-----------------+EXAMPLE - Base type
using FMyState = TSharedCustomState
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
IDisplayCluster::Get().GetClusterMgr()->UnregisterCustomState(MyStateName); // Unregister it from replication on this cluster node IDisplayCluster::Get().GetClusterMgr()->RegisterCustomState(MyStateName, MyState); // Register againEXAMPLE - 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 = TSharedCustomState
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
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 | TSharedCustomState |
| Type | class |
| Header File | /Engine/Plugins/Runtime/nDisplay/Source/DisplayCluster/Public/Cluster/CustomStates/DisplayClusterCustomStateShared.h |
| Include Path | #include "Cluster/CustomStates/DisplayClusterCustomStateShared.h" |
Syntax
template<typename TDataType>
class TSharedCustomState :
public UE::nDisplay::Private::TCustomStateData< TDataType > ,
public UE::nDisplay::Private::TCustomStateFactory< TSharedCustomState< TDataType > >
Inheritance Hierarchy
- TCustomStateFactory → TSharedCustomState
Implements Interfaces
Constructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
| Private constructor. Only factory method can instantiate this class. | Cluster/CustomStates/DisplayClusterCustomStateShared.h |
Destructors
| Name | Remarks | Include Path | Unreal Specifiers |
|---|---|---|---|
virtual ~TSharedCustomState() |
Cluster/CustomStates/DisplayClusterCustomStateShared.h |
Typedefs
| Name | Type | Remarks | Include Path |
|---|---|---|---|
| ThisType | TSharedCustomState< TDataType > | Cluster/CustomStates/DisplayClusterCustomStateShared.h |