the -1 is the key, the 15.0f is how long to display it in seconds, the color is obviously the color to print, and the final param is obviously the message that you want printed which is an FString
using -1 as the key tells it that duplicate messages are ok. meaning that rather than update the same message it will create a new one and print that. If you want to reuse the same message just use a key != -1.
and normally I just use FString::FromInt or FString::SanatizeFloat for numbers. Personally I never check to make sure GEngine is valid before calling because I wrap this in a debug check so it will never make it to production and I also never need to worry about removing it. I also use the same #if to set things like bDrawDebugViewTrace and bShowHitBoxDebugInfo.
GEngine->AddOnScreenDebugMessage(-1,
5.f, FColor::Red, FString::Printf(TEXT(“StartTCPReceiver>>
Listen socket could not be created! ~>
%s %d”), *TheIP, ThePort));
It’s good practice to make sure GEngine is valid before you call the method.
You can also run your project in VS debugger. Put breakpoints on points you interested in to check the states (you can do that by clicking on left side of code line you want to break) and then click on start debugging, or attach to project if you already running UE4. During a break you can explore variable states, as well as execute code step by step letting you see how your code is executed, debugger also let you notice on which point your code is crashing.
Debugger works the best if you got engine build from source in debug build configuration, you might have problems with development and release configurations. This also let you debug engine code.
I recently wrote a full header file for the community, that I use myself all the time, which lets you automatically print out the class and line number where you send a message to the screen from C++!
UE4 Forum Link ~ Print Class and Line Number along with your Screen Messages!
In this pic, AEVCoreDefense is my C++ Class, and the line number of the screen message is currently line 93 (automatically updates as your class grows in size!)
It’s really baffling to me that epic would destroy all of their old doc links in whatever migration they did. So many of these answers are now incomplete.