Say I have a class that I would like to access like this (from anywhere in the project):
MyGlobalSettings->Timeout = 4.0f; // set something
lastJoinedGame = MyGlobalSettings->LastJoinedGame // get something
MyGlobalSettings->TreeDensity = 0.02f; // set something
MyGlobalSettings->Save() // save current values to INI-file
Basically a singleton that is available anywhere in the project and that loads before anything else (so that it can initialize/load it’s settings from INI before another class requires them).
But I heard that object-singletons require a reference in order not to be garbage collected… So what is the most proper way in Unreal to have global settings that are stored&saved to/from inifile?
This is what my test example looks like so far:
#pragma once
#include "UObject/NoExportTypes.h"
#include "ServerConfig.generated.h"
UCLASS(Config = ServerConfig)
class TEST_API UServerConfig : public UObject
{
GENERATED_BODY()
UPROPERTY(Config)
float SomeVariable = 0.12f; // This value is not written to inifile... Probably because the class is not a singleton yet.
};
Or should I just dump it all into the GameInstance? I suppose that the GameInstance loads before most other objects, is a singleton and is thus accessible anywhere. I’m not 100% sure if this would work for multiplayer though.