Read and write from file config

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 ?

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

Also:



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

    LoadConfig();
}


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

“AShipgetvariable()” is not necessary.

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

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

can someone help ?

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