add on screen debug message ue4

// Include necessary header files
#include "YourGameMode.h" // Replace with the actual name of your GameMode header file
#include "Engine/Engine.h" // Include the Engine header file

// In your class implementation file (e.g., YourGameMode.cpp), within a member function or wherever appropriate:

// Create a FString variable to store your debug message
FString DebugMessage = TEXT("Your Debug Message Here");

// Use the GEngine global variable to access the AddOnScreenDebugMessage function
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, DebugMessage);

Replace "YourGameMode" with the actual name of your GameMode class. Adjust the value of DebugMessage to the desired debug message you want to display on the screen. The parameters for AddOnScreenDebugMessage are as follows:

  • -1: Specifies the key for this message. Use -1 for a unique key.
  • 5.f: Specifies the time (in seconds) the message will be displayed on the screen.
  • FColor::Red: Specifies the color of the debug message. You can choose from various predefined colors or create your own using FColor(R, G, B, A) where R, G, B, and A are values between 0 and 255.
  • DebugMessage: The actual message you want to display. Replace it with your desired debug information.