DrawText not displaying when packaged

I use the DrawText function in the DrawHUD call in c++ to draw strings and It works correctly when i play in the editor buy when i play it after packaging no strings are displayed

I Use the following code to display strings on the screen:

.h
#pragma once

#include "GameFramework/HUD.h"
#include "MainHUD.generated.h"

USTRUCT(BlueprintType)
struct FDisplayString
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MOO)
	FString Text;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MOO)
	FVector2D Position;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MOO)
	FColor Color;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MOO)
	FVector2D Scale;
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MOO)
	int32 DisplayTime;

	int32 StartTime;
};

/**
 * 
 */
UCLASS()
class MOONSHINEWORKS_API AMainHUD : public AHUD
{
	GENERATED_BODY()
public:
	AMainHUD(const class FObjectInitializer& PCIP);

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MOO)
	UFont* Font;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MOO)
	TArray<FDisplayString> DisplayStrings;

	UFUNCTION(BlueprintCallable, Category = MOOnshine)
	void AddDisplayString(FDisplayString DisplayStringToAdd);

protected:
	void DrawHUD() override;
	virtual void Tick(float DeltaSeconds) override;
};

.cpp

#include "MOOnshineWorks.h"
#include "MainHUD.h"


AMainHUD::AMainHUD(const class FObjectInitializer& PCIP)
: Super(PCIP)
{

}


void AMainHUD::DrawHUD()
{
	Super::DrawHUD();

	int DisplayStringsCount = DisplayStrings.Num();

	for (int i = DisplayStringsCount - 1; i >= 0; i--)
	{
		FDisplayString* DisplayString = &DisplayStrings[i];

		FVector2D Position = FVector2D(DisplayString->Position.X, DisplayString->Position.Y + i * 20);
		DrawText(DisplayString->Text, Position, Font, DisplayString->Scale, DisplayString->Color);
	}
}

void AMainHUD::AddDisplayString(FDisplayString DisplayStringToAdd)
{

	int32 DisplayStringsCount = DisplayStrings.Num();

	for (int32 i = 0; i < DisplayStringsCount; i++)
	{
		if (DisplayStrings[i].Text == DisplayStringToAdd.Text)
		{
			return;
		}
	}
	DisplayStringToAdd.StartTime = FDateTime::Now().ToUnixTimestamp();

	DisplayStrings.Add(DisplayStringToAdd);
}

void AMainHUD::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	int DisplayStringsCount = DisplayStrings.Num();
	FDateTime CurrentTime = FDateTime::Now();

	for (int i = DisplayStringsCount - 1; i >= 0; i--)
	{

		FVector2D Position = FVector2D(DisplayStrings[i].Position.X, DisplayStrings[i].Position.Y + i * 20);

		if (DisplayStrings[i].DisplayTime == 0)
		{
			DisplayStrings.RemoveAt(i, 1);
		}
		else if (DisplayStrings[i].DisplayTime <= CurrentTime.ToUnixTimestamp() - DisplayStrings[i].StartTime)
		{
			DisplayStrings.RemoveAt(i, 1);
		}
	}
}

I tried replacing the c++ code in DrawHUD to blueprints and now it crashed when i call DrawText

So for testing sake i called only Draw Text on the Draw HUD event in the HUD blueprint and it doesn’t crash but it still doesn’t display any string on the screen after the game is packaged

For my sake… and possibly others, could you post up your GameMode.cpp?

Make sure in your constructor you have the following set.

HUDClass = A<YourHudClass>::StaticClass();

GameMode.cpp

AMOOnshineWorksGameMode::AMOOnshineWorksGameMode(const class FObjectInitializer& PCIP)
	: Super(PCIP)
{

	NextStreamingLevelToLoad = 0;
	NextStreamingLevelToUnLoad = 0;

	if (GetWorld()){

		SaveManager = (ASaveManager*)GetWorld()->SpawnActor(ASaveManager::StaticClass());
		SaveManager->Load();

		// set default pawn class to our Blueprinted character
		ConstructorHelpers::FClassFinder<APawn> BP(TEXT("/Game/Blueprints/MyCharacter"));
		DefaultPawnClass = BP.Class;

		static ConstructorHelpers::FObjectFinder<UBlueprint> HUD(TEXT("Blueprint'/Game/Blueprints/HUDBlueprints/MainHud.MainHud'"));
		if (HUD.Object != NULL)
		{
			HUDClass = (UClass*)HUD.Object->GeneratedClass;
		}
	}
}

I believe i copied the code from a tutorial somewhere.

So i changed the way i set the HUD class too the way i set the defualt pawn class because the HUD class not being said would explain some things.

AMOOnshineWorksGameMode::AMOOnshineWorksGameMode(const class FObjectInitializer& PCIP)
	: Super(PCIP)
{
	NextStreamingLevelToLoad = 0;
	NextStreamingLevelToUnLoad = 0;

	if (GetWorld()){

		SaveManager = (ASaveManager*)GetWorld()->SpawnActor(ASaveManager::StaticClass());
		SaveManager->Load();

		// set default pawn class to our Blueprinted character
		ConstructorHelpers::FClassFinder<APawn> PawnBP(TEXT("/Game/Blueprints/MyCharacter"));
		DefaultPawnClass = PawnBP.Class;

		ConstructorHelpers::FClassFinder<AHUD> HUDBP(TEXT("/Game/Blueprints/HUDBlueprints/MainHud"));
		HUDClass = HUDBP.Class;
	}
}

And it worked perfectly :smiley:

Thanks for the suggestion been trying to solve this issue for hours now

Thanks to Master Kyp i chanced the way i set the Default HUD class in the gamemode constructor from:

static ConstructorHelpers::FObjectFinder<UBlueprint> HUD(TEXT("Blueprint'/Game/Blueprints/HUDBlueprints/MainHud.MainHud'"));
         if (HUD.Object != NULL)
         {
             HUDClass = (UClass*)HUD.Object->GeneratedClass;
         }

Too:

ConstructorHelpers::FClassFinder<AHUD> HUDBP(TEXT("/Game/Blueprints/HUDBlueprints/MainHud"));
		HUDClass = HUDBP.Class;

And now it works as intended.