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"

How to store variables to a custom .ini file?

Hey guys I've been using UE4 C++ for the past 6 months and I still don't know exactly how to do this. I am trying to create config variables for user gameplay preferences and graphics settings that would be stored on a custom .ini file. This is what I have now,

 UCLASS(config=UserSettings)
 class UQuantumUserSettings : public UGameUserSettings
 {
     GENERATED_BODY()
     
 public:
 
     /********************/
     /* Gameplay Settings*/
     /********************/
 
     UPROPERTY(Config)
     bool ToggleSprint;
 
     UPROPERTY(Config)
     bool ToggleCrouch;
 };

This complies with no problems and it generates an .ini file called UserSettings, but the file is blank. Am I on the right track? Can someone maybe show me how to do this correctly?

Product Version: UE 4.8
Tags:
more ▼

asked Aug 29 '15 at 06:16 AM in C++ Programming

avatar image

MajesticMack
28 1 2 6

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

4 answers: sort voted first

This is an old question but I was having the same problem and happened across the solution, so I figured I'd post it for posterity. Here's how it works:

Your c++ class definition should look like this.

 UCLASS(config=NewConfigFileName)
 class YOURGAME_API AExample : public AActor
 {
     GENERATED_BODY()
 
     UPROPERTY(Config)
           int32 test_number;
     UPROPERTY(Config)
           FString test_string;
 }

Edit: Oh and I almost forgot, you can have other properties in your UPROPERTY declaration.

As you noted the UCLASS declaration will automatically create an empty .ini file for you at compile time. Open up that file and type this inside it:

 [/Script/YourGame.Example]
 test_number=1
 test_string=hi
 

Note how I typed Example in the config file and not AExample. Now whatever values you assigned in the ini file will automatically be loaded into your c++ variables. However, if you want to make a change to the ini file you'll have to completely close out and reload the editor. I haven't yet found a way to reload values on the fly and I'm not sure there is one. You can find more info in the documentation here: https://docs.unrealengine.com/latest/INT/Programming/Basics/ConfigurationFiles/index.html

more ▼

answered Mar 12 '16 at 05:27 AM

avatar image

chrisrf
71 3 13 8

avatar image CleanCut Apr 20 '16 at 10:45 PM

Thank you! This helped me a ton.

One thing to note is you have to add Default to the start of the config file if you want a default one in Config/

To make this usable in a Blueprint I had to slightly alter your code to be more like this:

 UCLASS(config=NewConfigFileName, Blueprintable, BlueprintType)
  class YOURGAME_API AExample : public AActor
  {
      GENERATED_BODY()
  
 public:
      UPROPERTY(Config, BlueprintReadOnly)
            int32 test_number;
      UPROPERTY(Config, BlueprintReadOnly)
            FString test_string;
  }
avatar image RHZhang May 28 '18 at 12:42 PM

There's an importance part here... the section name must be [/Script/<project_name>.<class_name>]. I spent too much on this today.

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

If the file was created, that's a very good sign.

Have you tried adding your settings to see whether it makes a difference?

At least for Blueprint classes, the syntax is

 [/Game/CONTENTPATH/CLASSNAME.CLASSNAME_C]
 VARIABLE = SETTING

... where CONTENTPATH is the path within the Content directory.

In the below example, I've added a configurabe variable to the class TestActor, which lies in PROJECTPATH/Content/TopDownBP/Blueprints:

 [/Game/TopDownBP/Blueprints/TestActor.TestActor_C]
 TestVarEditable=201

If that doesn't work, try leaving off the "_C" syntax. I think that might be Blueprint-only.

more ▼

answered Aug 29 '15 at 07:05 AM

avatar image

erinacea
1.8k 69 28 114

avatar image MajesticMack Aug 29 '15 at 07:56 AM

That didn't work and im doing c++ btw

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

Did you see this: https://wiki.unrealengine.com/Config_Files,_Read_%26_Write_to_Config_Files ? Especially the safe path: YourGame\Saved\Config\Windows .

more ▼

answered Aug 29 '15 at 01:56 PM

avatar image

Timoses
91 14 14 22

avatar image MajesticMack Aug 29 '15 at 06:49 PM

I've read that many times but it doesn't show how to write to a custom ini file. I want my variables to be in a separate ini file not with the defaultgame.ini.

avatar image RVillani Dec 19 '18 at 09:42 AM

For writing to custom ini file, instead of using one of the globals as file name (GGameIni etc), you need to pass in your file's absolute path. For instance, if I want to save data in an ini called DefaultMyGame.ini stored in [Project]/Config, I'll use as path FPaths::ProjectConfigDir() / TEXT("DefaultMyGame.ini").

And for the section, it's as others said: /Script/YourProjectName.ClassName
If it is a plugin, it'll be /Script/ModuleName.ClassName

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

Hi guys, I have a question about this:

consider that I have my project cooked with some default settings, but on a specific machine I want to change them. How can I override the values in .ini that has been packaged?

Thank you

more ▼

answered Jun 08 '16 at 02:26 PM

avatar image

littlerussian
21 1 3 6

(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