# Read and write from file config

**URL:** <https://forums.unrealengine.com/t/read-and-write-from-file-config/127776>\
**Category:** C++\
**Tags:** unreal-engine\
**Created:** [June 20, 2019, 12:27pm UTC](https://forums.unrealengine.com/t/read-and-write-from-file-config/127776 "2019-06-20T12:27:46Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![anonymous\_user\_a05fcd9c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a05fcd9c](https://forums.unrealengine.com/u/anonymous_user_a05fcd9c)\
**Post date:** [June 20, 2019, 12:27pm UTC](https://forums.unrealengine.com/t/read-and-write-from-file-config/127776/1 "2019-06-20T12:27:46Z")

</div>

HI all, i’m trying to read data from new config file

.h

#pragma once

#include “CoreMinimal.h”  
#include “GameFramework/Actor.h”  
#include “Ship.generated.h”

UCLASS(Config=Configproject)  
class UDP\_SENDER\_API AShip : public AActor  
{  
GENERATED\_BODY()

public:  
// Sets default values for this actor’s properties  
AShip();

protected:  
// Called when the game starts or when spawned  
virtual void BeginPlay() override;

public:  
// Called every frame  
virtual void Tick(float DeltaTime) override;  
UPROPERTY(EditAnywhere)  
UStaticMeshComponent\* Mesh;  
int AShipgetvariable();

```
UPROPERTY(Config)
    int ExampleVariable;

```

};

.cpp

#include “Ship.h”  
#include “Misc/ConfigCacheIni.h”  
#include “GameFramework/PlayerController.h”

// Sets default values  
AShip::AShip()  
{  
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don’t need it.  
PrimaryActorTick.bCanEverTick = true;  
Mesh = CreateDefaultSubobject\<UStaticMeshComponent\>(“MyMesh”);

}

// Called when the game starts or when spawned  
void AShip::BeginPlay()  
{  
Super::BeginPlay();  
}

// Called every frame  
void AShip::Tick(float DeltaTime)  
{  
Super::Tick(DeltaTime);  
ExampleVariable = AShipgetvariable();

}

int AShip::AShipgetvariable()  
{  
int ExampleVariable = 2;  
if (!GConfig) return -1;

```
FString Configproject = FPaths::GeneratedConfigDir().Append(TEXT("Configproject.ini"));
GConfig-&gt;GetInt(
    TEXT("/Script/UDP_sender.Ship"),
    TEXT("ExampleVariable"),
    ExampleVariable,
    Configproject
);

UE_LOG(LogTemp, Log, TEXT("ExampleVariable %d 

```

"), (int)ExampleVariable);

```
return ExampleVariable;

```

}

the .ini

[/Script/UDP\_sender.Ship]  
ExampleVariable=5

it’s don’t,work someone know why ?

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [June 20, 2019, 1:38pm UTC](https://forums.unrealengine.com/t/read-and-write-from-file-config/127776/2 "2019-06-20T13:38:46Z")

</div>

“config”, lowercase (because epic much consistent huh).

Also:

```auto

AShip::AShip()
{
    PrimaryActorTick.bCanEverTick = true;
    Mesh = CreateDefaultSubobject<UStaticMeshComponent>("MyMesh");

    LoadConfig();
}

```

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a05fcd9c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a05fcd9c](https://forums.unrealengine.com/u/anonymous_user_a05fcd9c)\
**Post date:** [June 20, 2019, 2:01pm UTC](https://forums.unrealengine.com/t/read-and-write-from-file-config/127776/3 "2019-06-20T14:01:37Z")

</div>

i change UCLASS(Config=Configproject) to UCLASS(config=Configproject) and add LoadConfig(); but still dosn’t work

---

<div class="post-metadata">

**Author:** ![BrUnO\_XaVIeR](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/bruno_xavier/32/1110230_2.png) [@BrUnO\_XaVIeR](https://forums.unrealengine.com/u/BrUnO_XaVIeR)\
**Post date:** [June 20, 2019, 2:43pm UTC](https://forums.unrealengine.com/t/read-and-write-from-file-config/127776/4 "2019-06-20T14:43:09Z")

</div>

“AShipgetvariable()” is not necessary.

“LoadConfig()” should already load the values from ini into the class, so no need to call “ExampleVariable = AShipgetvariable();” like that.

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a05fcd9c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a05fcd9c](https://forums.unrealengine.com/u/anonymous_user_a05fcd9c)\
**Post date:** [June 21, 2019, 6:34am UTC](https://forums.unrealengine.com/t/read-and-write-from-file-config/127776/5 "2019-06-21T06:34:19Z")

</div>

Still don’t work

[/Script/UDP\_sender.Ship]  
is it correct ? knowing that UDP\_sender is the name of my project and Ship the name of the class

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a05fcd9c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a05fcd9c](https://forums.unrealengine.com/u/anonymous_user_a05fcd9c)\
**Post date:** [June 24, 2019, 8:37am UTC](https://forums.unrealengine.com/t/read-and-write-from-file-config/127776/6 "2019-06-24T08:37:50Z")

</div>

can someone help ?

---

<div class="post-metadata">

**Author:** ![anonymous\_user\_a05fcd9c](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@anonymous\_user\_a05fcd9c](https://forums.unrealengine.com/u/anonymous_user_a05fcd9c)\
**Post date:** [June 24, 2019, 12:39pm UTC](https://forums.unrealengine.com/t/read-and-write-from-file-config/127776/7 "2019-06-24T12:39:18Z")

</div>

It work !!  
The config file was created in PROJECT\Intermediate\Config\CoalescedSourceConfigs

The solution was: create config file in PROJECT\Saved\Config\Windows and set it up then re-build
