Download

C++ how to add a float to the gamemode

I’m trying to add a public float to my Gamemode in C++, And I’m able to do that, but I can’t get the float value in Blueprint. can someone help me with that?
Here are my codes:
.H

#pragma once

#include “CoreMinimal.h”
#include “GameFramework/GameModeBase.h”
#include “SetKeysGameMode.generated.h”

UCLASS(minimalapi)
class ASetKeysGameMode : public AGameModeBase
{
GENERATED_BODY()

public:
ASetKeysGameMode();

UPROPERTY(EditAnywhere, BlueprintReadOnly)
float SPD = 9.0f;

};

C++

#include “SetKeysGameMode.h”
#include “SetKeysCharacter.h”
#include “UObject/ConstructorHelpers.h”

ASetKeysGameMode::ASetKeysGameMode()
{
// set default pawn class to our Blueprinted character
static ConstructorHelpers::FClassFinder PlayerPawnBPClass(TEXT("/Game/ThirdPersonCPP/Blueprints/ThirdPersonCharacter"));
if (PlayerPawnBPClass.Class != NULL)
{
DefaultPawnClass = PlayerPawnBPClass.Class;
}
}

ASetKeysGameMode::SetTime()
{
public void SPD()
{
SPD = (9.0f);;
}
}

You will need to change BlueprintReadOnly to BlueprintReadWrite

BlueprintReadOnly should be enough for a getter.

Try compiling the project with the editor closed.

Hey there,

Could you please format your code with three (`)s around the top and bottom?