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->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 ?