Live Config
Loading...
Searching...
No Matches
LiveConfigSystem.h
1// Copyright (c) 2026 Nicholas Arthur
2// Licensed under the MIT License
3
4#pragma once
5
6#include "UObject/UnrealType.h"
7#include "Subsystems/EngineSubsystem.h"
8#include "Interfaces/IHttpRequest.h"
9#include "CoreMinimal.h"
10#include "LiveConfigTypes.h"
11#include "LiveConfigPropertyName.h"
12#include "Profiles/LiveConfigProfile.h"
13#include "ConsoleSettings.h"
14#include "LiveConfigSystem.generated.h"
15DECLARE_MULTICAST_DELEGATE(FOnLiveConfigPropertiesUpdated);
16
17namespace LiveConfigTags
18{
19 const LIVECONFIG_API extern FName FromCurveTable;
20}
21
26UCLASS(BlueprintType, Config=Game, DefaultConfig)
27class LIVECONFIG_API ULiveConfigSystem : public UEngineSubsystem
28{
29 GENERATED_BODY()
30
31public:
32 FOnLiveConfigPropertiesUpdated OnPropertiesUpdated;
33
34 FSimpleMulticastDelegate OnTagsChanged;
35
41 static ULiveConfigSystem& Get();
42
43 // USubsystem
44 virtual void Initialize(FSubsystemCollectionBase& Collection) override;
45 virtual void Deinitialize() override;
46 virtual bool ShouldCreateSubsystem(UObject* Outer) const override;
47 // ~USubsystem
48
52 void SaveProperty(const FLiveConfigPropertyDefinition& PropertyDefinition);
56 void SavePropertyDeferred(const FLiveConfigPropertyDefinition& PropertyDefinition);
57
65 void RenameProperty(FLiveConfigProperty OldName, FLiveConfigProperty NewName, bool bCreateRedirector = false);
66
72 FString GetStringValue(FLiveConfigProperty Key) const;
73
75 float GetFloatValue(FLiveConfigProperty Key) const;
76
78 int32 GetIntValue(FLiveConfigProperty Key) const;
79
81 bool GetBoolValue(FLiveConfigProperty Key) const;
82
87 template<typename T>
89 {
90 T OutStruct;
91 UScriptStruct* Struct = TBaseStructure<T>::Get();
92 if (!Struct)
93 {
94 Struct = T::StaticStruct();
95 }
96 GetLiveConfigStruct_Internal(Struct, &OutStruct, StructProperty);
97 return OutStruct;
98 }
99
104 template<typename T>
106 {
107 RedirectPropertyName(Property);
108 return Cache.GetValue<T>(Property);
109 }
110
111 void GetLiveConfigStruct_Internal(class UScriptStruct* Struct, void* OutStructPtr, FLiveConfigProperty Prefix) const;
112
114 UFUNCTION(BlueprintCallable, Category = "Live Config")
115 bool IsDataReady() const { return bIsDataReady; }
116
117 void DownloadConfig();
118
120 void RebuildConfigCache();
121 void RebuildConfigCache(const FLiveConfigProfile& Profile);
122
124 UFUNCTION(BlueprintCallable, Category = "Live Config")
125 const TMap<FLiveConfigProperty, FLiveConfigPropertyDefinition>& GetAllProperties() const;
126
127 static bool DoesPropertyNameExist(FLiveConfigProperty PropertyName);
128
130 void RedirectPropertyName(FLiveConfigProperty& Property) const;
131
132
137 void RemoveRedirect(FName OldPropertyName);
138
139 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "General")
140 TMap<FLiveConfigProperty, FLiveConfigPropertyDefinition> PropertyDefinitions;
141
142 UPROPERTY(Config, VisibleAnywhere, BlueprintReadOnly, Category = "General")
143 TArray<FName> PropertyTags;
144
145 void HandleTagsChanged();
146
147
148 UPROPERTY(Config)
149 TMap<FName, FName> PropertyRedirects;
150
151
152private:
153 FString RemoteOverrideCSVUrl;
154 double TimeLoadStarted = -9999;
155 float RateLimitSeconds = 5;
156 FTimerHandle PollingTimer;
157 FTSTicker::FDelegateHandle TimeoutTimer;
158 TSharedPtr<IHttpRequest> CurrentRequest;
159
160 UPROPERTY()
161 FLiveConfigCache Cache;
162
163 // Environment config is treated as a layer below more specific profiles
164 FLiveConfigProfile EnvironmentOverrides;
165
166 float TimeoutDuration;
168 void OnSheetDownloadComplete(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful);
169
170 void OnTravel(UWorld* World, FWorldInitializationValues WorldInitializationValues);
171 void OnStartGameInstance(UGameInstance* GameInstance);
172
176 UFUNCTION()
177 void BuildCache();
178
179 void PopulateAutoCompleteEntries(TArray<FAutoCompleteCommand>& AutoCompleteCommands);
180
182 bool bIsDataReady = false;
183};
Definition LiveConfigSystem.h:28
T GetLiveConfigStruct(FLiveConfigProperty StructProperty) const
Definition LiveConfigSystem.h:88
T GetLiveConfigValue(FLiveConfigProperty Property) const
Definition LiveConfigSystem.h:105
Definition LiveConfigTypes.h:61
Definition LiveConfigProfile.h:24
Definition LiveConfigTypes.h:34
Definition LiveConfigPropertyName.h:14