So I’m making an HUD script for my game for debugging purpose, but when I want to draw a number on the screen that show the Ticking delta second, the number doesn’t change, it keeps showing “0” on the screen, how can I get rid of this problem?
PlayerHUD.h
#pragma once
#include "GameFramework/HUD.h"
#include "PlayerHUD.generated.h"
/**
* The Player Heads-up display manager class, responsible for handling and displaying the data from the Player.
*/
UCLASS(Config=Game)
class APlayerHUD : public AHUD
{
GENERATED_UCLASS_BODY()
public :
UPROPERTY(Config)
bool UseDebugCamera;
bool Debugging = true;
UFont* theFont;
float TickRate;
//Update data by every frame.
void UpdateData();
void Display();
void ConfigO();
void ConfigI();
void DrawFText(UFont* font, const FString& str, const float& X, const float& Y, const FLinearColor& textColor, const float& Scale);
virtual void Tick(float deltaSecond) override;
virtual void BeginPlay() override;
virtual void DrawHUD() override;
};
PlayerHUD.cpp
#include "../The_Haunting.h"
#include "PlayerHUD.h"
#include "../Public/PlayerPawn.h"
#include "../Public/PlayerInterface.h"
APlayerHUD::APlayerHUD(const class FPostConstructInitializeProperties& PCIP)
: Super(PCIP)
{
static ConstructorHelpers::FObjectFinder<UFont> theFontOBJ(TEXT("/Game/Data/UI/Exo_2"));
this->theFont = theFontOBJ.Object;
}
void APlayerHUD::UpdateData()
{
}
void APlayerHUD::Display()
{
}
void APlayerHUD::ConfigO()
{
if (!GConfig)
return;
FString Section = "Game.Debug";
GConfig->SetString(*Section, TEXT("UseDebugEyes"), TEXT("FALSE"), GGameIni);
GConfig->Flush(false, GGameIni);
}
void APlayerHUD::ConfigI()
{
if (!GConfig)
return;
FString boolOperator;
GConfig->GetString(TEXT("Game.Debug"), TEXT("UseDebugEyes"), boolOperator, GGameIni);
if (boolOperator == "TRUE" || boolOperator == "True" || boolOperator == "true")
{
APlayerHUD::Debugging = true;
}
else if (boolOperator == "FALSE" || boolOperator == "False" || boolOperator == "false")
{
APlayerHUD::Debugging = false;
}
else
{
return;
}
}
void APlayerHUD::Tick(float deltaSecond)
{
Super::Tick(deltaSecond);
APlayerHUD::TickRate = deltaSecond;
}
void APlayerHUD::BeginPlay()
{
Super::BeginPlay();
APlayerHUD::ConfigO();
APlayerHUD::ConfigI();
}
void APlayerHUD::DrawHUD()
{
Super::DrawHUD();
APlayerPawn* pawn = Cast<APlayerPawn>(GetOwningPawn());
FText FTickRate = FText::FromString(FString::FromInt(APlayerHUD::TickRate));
FLinearColor textColor = FLinearColor(1.0f, 1.0f, 1.0f);
if (!Canvas)
{
return;
}
if (APlayerHUD::Debugging)
{
Canvas->DrawText(this->theFont, FText::FromString(FString::FromInt(this->TickRate)), 1.0f, 1.0f);
}
}