x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

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.

Product Version: Not Selected
Tags:
more ▼

asked Sep 15 '14 at 09:42 AM in C++ Programming

avatar image

dezzzus
87 7 13 18

avatar image Commander Shepard Aug 19 '15 at 05:55 PM

Ayy! thats my pic you have :)

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

6 answers: sort voted first

jara is right but I prefer to call it like this:

 #if UE_BUILD_DEBUG
     GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Red, "debug msg");
 #endif

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.

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

more ▼

answered Sep 15 '14 at 10:07 AM

avatar image

RuBa1987
484 24 21 52

avatar image Shadowriver Mar 02 '15 at 05:11 PM

I deleted the duplicated anwser

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

 UE_LOG(LogTemp, Log, TEXT("Your message"));

You can learn more from THIS LINK:

more ▼

answered Mar 02 '15 at 05:09 PM

avatar image

CanMetan
91 9 58 15

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

AddOnScreenDebugMessage (usage below):

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.

more ▼

answered Sep 15 '14 at 09:46 AM

avatar image

jaragoondoo
354 13 9 25

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Mar 02 '15 at 05:20 PM

avatar image

Shadowriver
37.2k 936 172 1116

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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!)

alt text

more ▼

answered Jul 23 '15 at 08:07 PM

avatar image

Rama
10.6k 446 346 1088

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

You can use:

The right way according to UE docs

 GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::White, TEXT("YOUR DEBUG MESSAGE"));

Note: You need to include Engine.h to your projects .cpp header. The EngineMinimal.h wont cut it.

See Print To Viewport

alt text

more ▼

answered Apr 16 '16 at 01:16 AM

avatar image

volkmedia
26 3 3

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question