Debugmessage nullpointer?!

Hello UE community,

i use this line in a method of a created Actor class, without it, everything works.

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("..."));

And I get this exception

Unhandled exception at 0x00007FFD5A87F5E4 (UE4Editor-Engine.dll) in UE4Editor.exe: 0xC0000005: Access violation reading location 0x0000000000000778.

The compiling stop at the if command from UnrealEngine.cpp

/** Wrapper from int32 to uint64 */
void UEngine::AddOnScreenDebugMessage(int32 Key, float TimeToDisplay, FColor DisplayColor, const FString& DebugMessage)
{
	if (bEnableOnScreenDebugMessages == true)
	{
		AddOnScreenDebugMessage( (uint64)Key, TimeToDisplay, DisplayColor, DebugMessage);
	}
}

What I’m doing wrong?

Greetings!

You need to have UE_BUILD_DEBUG as your build type for that line to work and

 #if UE_BUILD_DEBUG
     GEngine->AddOnScreenDebugMessage(-1, 2.0f, FColor::Red, "Some Message");
 #endif

would be the proper way

Generally messages to the screen are printed something like this

 UE_LOG(MyGame, Log, TEXT("Some Messsage") );

I highly reccomend reading Ramas post about debugging and printing messages here

Hope this helps
Don’t forget to accept an answer that best clears your question up or answers it so when the community finds your question in the future via search/google they know exactly what you did to fix it/get it going.