How To Make Static Helper Function that Prints Text to the Screen?

Hello. I want to make a static helper library, which prints the text to the game screen. I tried this code but it gives error.

Helper.h:

#pragma once

#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "Helper.generated.h"

/**
 * 
 */
UCLASS()
class BETHEONE_API UHelper : public UObject
{
	GENERATED_BODY()
	
	public:
	static void PrintToScreen(FString String);
	
	
};

Helper.cpp:

#include "Helper.h"

void PrintToScreeen(FString String)
{
	if (GEngine) {
		GEngine->AddOnScreenDebugMessage(-1, 5.0f, FColor::White, *String);
	}
}

The error:
When I try to call the function like UHelper::PrintToScreen(TEXT(“Something”)); and first including like #include “Helper.h”, it gives two errors. First of all, it says identifier "GEngine" is undefined, and second one is just a crash without any trace.

What is the problem? I am using the version 4.20.1.

To fix the “GEngine is undefined” problem, you need to put this in the .h file

#include "Engine.h"

It fixed the problem. Thanks. But still crashes. :frowning:

Weird. I tested this out myself and it seems to work fine

void ARTSCharacter::PrintToScreen(FString String)
{
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, *String);
	}
}

void ARTSCharacter::callstring()
{
	PrintToScreen("test");
}

are you calling with a different kind of parameter for the string?

No no, I’m calling the method from another class. That’s why it’s crashing. You called the method from same class.