Navigation
API > API/Runtime > API/Runtime/NetCore
State Structs
State structs implement an extensible way to use UPROPERTY's to set up 'state' variables in a USTRUCT, define many different named 'states' and set their default values (with the easy ability to override their values from the .ini file), and apply named states to a 'live'/active instance of the state struct (using UPROPERTY reflection, so that it's mostly automatic).
This has many of the benefits of UCLASS reflection and configuration, without the overhead - and implements more intuitive .ini configuration.
State Struct Definition
Override 'InitConfigDefaultsInternal' to set default values for each state (StateName specifies the current state).
State Struct Implementation
To implement loading for a custom state struct, extend from 'UStatePerObjectConfig' and define a UPROPERTY for the state names, e.g: TArray
Then create a variable to hold the state defaults ('FEscalationState' here is a subclass of 'FStateStruct'): TArray
Override 'LoadStateConfig' and use 'RegisterStateConfig' to link the state names to the state defaults (which will automatically be populated): RegisterStateConfig(EscalationSeverity, EscalationSeverityState);
Override 'InitConfigDefaultsInternal' to set default values for the state names, and to set bEnabled to true (if desired by default).
State Struct Usage
To use state structs, call and store the result of 'UStatePerObjectConfig::Get', specifying the configuration settings and classes to use, e.g: UEscalationManagerConfig* BaseConfig = CastChecked
The resulting UStatePerObjectConfig subclass object will contain all of the default states as set by 'RegisterStateConfig', and 'ApplyState' can be used to apply default states, to an active state instance.
To define an active state instance in an arbitrary class, specify: TStructOnScopeLite
To apply a default state to an active state instance, call: UStatePerObjectConfig::ApplyState(BaseConfig->EscalationSeverityState[StateIdx], State.Get());
NOTE: It's safe to store the config UObject without worrying about garbage collection, as there will only be one instance and it's added to root.
Configuration and Defaults
Default/hardcoded values are implemented for UStatePerObjectConfig and FStateStruct by overriding 'InitConfigDefaultsInternal'. In both cases, .ini settings can be specified, which override the hardcoded defaults.
State structs have non-standard ini configuration, with the following components for .ini section names:
- ConfigSection: The base configuration section name, shared with all related state struct config sections (e.g. NetFault, RPCDoSDetection)
- ConfigContext: Additional context for modifying which UStatePerObjectConfig section is loaded (e.g. GameNetDriver/BeaconNetDriver)
- StateName: For the configuration of individual states, this specifies the state name
The main UStatePerObjectConfig .ini section follows this format: [ConfigContext ConfigSection]
Or if there is no ConfigContext specified: [ConfigSection]
The configuration for individual FStateStruct states follows this format: [ConfigSection.StateName] The result of a call to InitConfigDefaults
| Name | EInitStateDefaultsResult |
| Type | enum |
| Header File | /Engine/Source/Runtime/Net/Core/Public/Net/Core/Connection/StateStruct.h |
| Include Path | #include "Net/Core/Connection/StateStruct.h" |
Syntax
enum EInitStateDefaultsResult
{
Initialized,
NotInitialized,
}
Values
| Name | Remarks |
|---|---|
| Initialized | |
| NotInitialized |