How to Debug via C++?
I want to print a string on the screen during runtime for debug via c++. But i can't find true method for it.
asked Sep 15 '14 at 09:42 AM in C++ Programming
jara is right but I prefer to call it like this:
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
Here are the docs on this if you want to see how it works: https://docs.unrealengine.com/latest/INT/API/Runtime/Engine/Engine/UEngine/AddOnScreenDebugMessage/1/index.html
answered Sep 15 '14 at 10:07 AM
You requested a method for on screen message for debugging, but I prefer using logs on the "output" window.
On screen messages will disappear, but you can browse the log messages indefinitely.
You can learn more from THIS LINK:
AddOnScreenDebugMessage (usage below):
It's good practice to make sure GEngine is valid before you call the method.
answered Sep 15 '14 at 09:46 AM
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.
answered Mar 02 '15 at 05:20 PM
Full C++ Support Header File For You
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! https://forums.unrealengine.com/showthread.php?57154-New-Wiki-How-to-Get-a-UE4-FString-of-Calling-Class-Function-and-Line-Number-Rama&p=210060&viewfull=1#post210060
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!)
You can use:
The right way according to UE docs
Note: You need to include Engine.h to your projects .cpp header. The EngineMinimal.h wont cut it.
Follow this question
Once you sign in you will be able to subscribe for any updates here