4.9.2 AddOnScreenDebugMessage doesn't print when editor is not in game mode

Hi,

repro steps:

  1. Create new C++ project out of Blank template, dont add starter content

  2. When new project launches and Editor opens go to AddNew->New C++ Class. Add new class derived from Actor, name it MyActor

  3. Open MyActor.h in VS, add this code in class definition:

    bool ShouldTickIfViewportsOnly() const override { return true; }

This code enables actors to also tick in editor, not only during play. You can check it by attaching debugger to UnrealEngine and placing breakpoint in MyActor::Tick function. Execution will break regardles if editor is in normal or PIE mode.

  1. In MyActor.cpp in function Tick add this code:

     if (GEngine)
     	GEngine->AddOnScreenDebugMessage(0, 0.f, FColor::Red, "adf");
    
  2. Compile

  3. When editor hot reloads, create new blueprint, inherit after MyActor class.

  4. Put instance of this blueprint into the world

  5. Hit PIE. Notice message printed on the screen

  6. Stop PIE. Notice that there is no message printed. Error

thanks

2 Likes

Hey-

This is working as intended since the if(GEngine) line will return false until you being PIE. This can be tested by printing a message to the log window at the same time. The following examples assume the ShouldTickIfViewportOnly call is true. With this code:

if (GEngine)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("adafdaff"));
	UE_LOG(LogTemp, Warning, TEXT("Print On Tick"));
}

Both the DebugMessage and the Log warning only print during PIE. However, with the following change (moving the log outside of the if):

if (GEngine)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("adafdaff"));
}
	UE_LOG(LogTemp, Warning, TEXT("Print On Tick"));

The debug message will only print during PIE however the log message will continue to print after exiting PIE.

Cheers

1 Like

Hello Dough,

I think You messed up something with Your testing. I’ve just checked it and in my engine version (launcher 4.9.2) GEngine is definitively valid in normal editor mode (not PIE). So this code:

if (GEngine)
 {
     GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("adafdaff"));
     UE_LOG(LogTemp, Warning, TEXT("Print On Tick"));
 }

causes “Print on Tick” to be printed to output log no matter if I am in regular editor mode or PIE. Hovewer “asafdaff” gets printed only in PIE.

1 Like

I’m not sure what happened with my initial test however further testing gave the same result you described. After speaking with another engineer it appears that AddOnScreenDebugMessage implicitly goes to “the game’s current viewport”, which would imply that the game is currently running. If you are trying to print information from an actor’s Tick() function inside the editor (rather than PIE) I would try using log messages rather than attempting to print to the screen.

1 Like

I would try using log messages

I hoped You will not say this. Having possibility to print messages on screen not only during game but also during creating it in editor is really a necessity. Many many of the features are just tools created in editor for artist to use. Those tools also needs to be debugged, and also need to be able to talk to person that is using them. Using output log is extremely inconvenvenient. I am shure that there is possiblity to print text while in editor mode, there is just no simple way of doing it (and there should be one).

I would be grateful for the knowledge on how to print messages on screen while in editor mode.

1 Like

I’ve entered a feature request for printing messages to the screen rather than the output log in the editor (UE-23912).

1 Like

If you want ScreenDebugMessages to work outside of play mode try toggle FPS or Stats