Skip to content
Snippets Groups Projects
Select Git revision
  • 62366312fc2ea3746bc8d17b4b8f922d4fc48dda
  • 5.4 default protected
  • 5.5
  • dev/5.5
  • dev/5.4
  • dev/5.3_downgrade
  • feature/experimenttime_hack
  • 5.3 protected
  • _IntenSelect5.3
  • IntenSelect5.3
  • 4.27 protected
  • 4.26 protected
  • 5.0 protected
  • 4.22 protected
  • 4.21 protected
  • UE5.4-2024.1
  • UE5.4-2024.1-rc1
  • UE5.3-2023.1-rc3
  • UE5.3-2023.1-rc2
  • UE5.3-2023.1-rc
20 results

DemoConfig.h

Blame
  • DemoConfig.h 1.95 KiB
    #pragma once
    
    #include "CoreMinimal.h"
    #include "Engine/DeveloperSettings.h"
    #include "DemoConfig.generated.h"
    
    /**
     * This DeveloperSettings derivative has the following behavior:
     * 1. Creates a DefaultDemo.ini in your projects config folder (Name can be changed via "config =" parameter in UCLASS)
     * 2. Creates a settings page in the project settings (ProjectSettings|Game|Demo) for all UPROPERTY-s and stores all UPROPERTY-s with a "Config" flag into (1.), that are altered
     * 3. When packaged, creates a Demo.ini (without "Default") in the config directory of the game and dumps the contents of the DefaultDemo.ini into it
     * 4. When packaged, loads the config file from (3.) into this class
     * 5. Settings can be accessed from everywhere via `GetDefault<UYourSubClass>()->PropertyName`
     */
    UCLASS(Abstract, config = Demo, defaultconfig)
    class RWTHVRTOOLKIT_API UDemoConfig : public UDeveloperSettings
    {
    	GENERATED_BODY()
    
    	virtual FName GetCategoryName() const override { return "Game"; };
    
    #if WITH_EDITOR
    	virtual FText GetSectionText() const override { return FText::FromString("Demo"); };
    #endif
    
    	virtual void PostInitProperties() override
    	{
    		Super::PostInitProperties();
    
    		// Do not create/load this config file in the editor. We have the DefaultDemo.ini already
    		if (FApp::GetBuildTargetType() == EBuildTargetType::Editor) return;
    
    		// Load config file (does nothing if not exist)
    		const FString ConfigFile = FPaths::Combine(FPaths::ProjectConfigDir(),
    		                                           FPaths::GetCleanFilename(GetClass()->GetConfigName()));
    		FConfigCacheIni Config(EConfigCacheType::DiskBacked);
    		Config.LoadFile(ConfigFile);
    
    		// Check existence of correct section (fails if file does not exist)
    		if (Config.DoesSectionExist(*GetClass()->GetPathName(), ConfigFile))
    		{
    			LoadConfig(GetClass(), *ConfigFile);
    		}
    		else
    		{
    			SaveConfig(CPF_Config, *ConfigFile, &Config);
    			Config.Flush(false);
    		}
    	};
    };