How to print debug output in C++ from OnConstruction()?

I want to print a string from the OnConstruction() function, which is the C++ equivalent of the construction script.

The standard method works from the Tick() function but doesn’t work from the OnConstruction() function, presumably because GEngine is null when the game is not running:

if (GEngine)
{
    GEngine->AddOnScreenDebugMessage(-1, TimeToDisplay, Color, Text);
}

Any other way this can be done?

Hm, i just searched the API for GEngine. It is a pointer to the UEngine which is the base class of all Engine classes. UEngine got the AddOnScreenDebugMessage, so if GEngine is null, the pointer has no reference to the UEngine. The bad thing is, i couldn’t find any information about the chronological order of the initialization of this UEngine etc. so i can’t tell you if the Pointer is just null because it wasn’t set by now (so you could use something else than this pointer) or if the whole UEngine isn’t initialized at this point.

Have you tried checking if the OnConstruction() is called at all? You could try using a normal Log Debug etc.

EDIT: Would be nice to know where GEngine is set :X I can’t find that for now.

Thanks eXi for the solution. I used UE_LOG() for the construction-time logging.

Also GEngine is indeed not null. The GEngine->AddOnScreenDebugMessage() executes but does nothing.

Modified solution:

static FORCEINLINE void Print(FString Text, bool PrintToLog = false, FColor Color = FColor::Green, float TimeToDisplay = 1.0f)
{
	if (GEngine)
	{
		GEngine->AddOnScreenDebugMessage(-1, TimeToDisplay, Color, Text);
	}

	if (PrintToLog)
	{
		UE_LOG(LogTemp, Warning, TEXT("%s"), *Text);
	}
}

@eXi: Solved. Turns out that OnConstruction was being called, and GEngine wasn’t null. GEngine->AddOnScreenDebugMessage() simply did nothing. UE_LOG worked. Thanks.