x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Config not being saved (UPROPERTY, UCLASS)

Hi !

I'm trying to save some variables into a config file, i followed every solution i found on the web/answerhub but nothing seems to work.

I checked in /Config and /Saved/Config/[Platform]/ no variable is saved, i tried UCLASS(Config=) with uppercase and lowercase (i saw both on example) and of course other config file name. And i tried to delete the /Saved folder and even multiple full project recompilation (by deleting /Saved /Intermediate/ /Binary

Where am i wrong ?

 UCLASS(config=Game, defaultconfig)
 class CONFIGTEST_API AMyPlayerController : public APlayerController
 {
     GENERATED_BODY()
 
 public:
     AMyPlayerController();
 
     void Tick(float DeltaTime) override;
 
 
 public:
 
     UPROPERTY(config, EditAnywhere, BlueprintReadWrite)
     FString        superVar = "OK";
 
     UPROPERTY(config)
     float        superFloat = 999;
 };

Thanks in advance !

Product Version: UE 4.16
Tags:
more ▼

asked May 31 '17 at 12:47 PM in C++ Programming

avatar image

gundz
32 4 7 9

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

You shouldn't be assigning values to the config variables within the header file.

You can set default values within the appropriate default config file (in your instance "GAMENAMEGame.ini", wherein "GAMENAME" is the actual name of your game) under a heading for your class holding the config variables:

 [/Script/GAMEMODULE.AMyPlayerController]
 superVar=OK
 superFloat=999.0f


Replace "GAMEMODULE" with the actual name of your game module.

Then, when you run your game, the values within the config file will be read into the variables in your class.

The values will only appear within the "/Saved/Config/[Platform]/" files if they are different from the default; otherwise the default values will be used.

In order to modify them, you have to use the GConfig global:

 if (GConfig)
 {
     GConfig->SetString(
         TEXT("/Script/GAMEMODULE.AMyPlayerController"),
         TEXT("superVar"),
         TEXT("Not Okay"),
         GGameIni
     );
     GConfig->SetFloat(
         TEXT("/Script/GAMEMODULE.AMyPlayerController"),
         TEXT("superFloat"),
         100.0f,
         GGameIni
     );
 }

GConfig also has SetText, SetInt, SetBool, SetColor, SetVector, and SetRotator to store other types of variables. FName values should be converted to FString when storing.

The section and key arguments can be held in an FString, but will need to be passed in via pointer. Values are passed normally:

 FString Section = TEXT("/Script/GAMEMODULE.AMyPlayerController");
 FString Key = TEXT("superVar");
 FString Value = TEXT("Not Okay");
 
 if (GConfig)
 {
     GConfig->SetString(*Section, *Key, Value, GGameIni);
 }
 

After setting the values, you need to flush the config file to ensure they are applied:

 if (GConfig)
 {
     GConfig->Flush(false, GGameIni);
 }

Or, from within your UCLASS(Config) object you can call "SaveConfig();"

You can also read from config files into any variable, without using the UCLASS and UPROPERTY specifiers:

 FString ValueReceived;
 if (GConfig)
 {
     GConfig->GetString(
         TEXT("/Script/GAMEMODULE.AMyPlayerController"),
         TEXT("superVar"),
         ValueReceived,
         GGameIni
     );
 }


https://docs.unrealengine.com/latest/INT/Programming/Basics/ConfigurationFiles/index.html

https://wiki.unrealengine.com/Config_Files,_Read_%26_Write_to_Config_Files

more ▼

answered May 31 '17 at 01:36 PM

avatar image

GigasightMedia
1.7k 42 12 61

avatar image gundz May 31 '17 at 01:48 PM

Okay i will try that.

Thanks a lot, very explicit !

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question