UE_LOG only once?

When using UE_LOG to log an information on output log, there is a way to write the log only once, even if the UE_LOG is inside a TICK() function, without having do any kind of execution flow control with a if statement?

I stumbled upon UE_CLOG(Condition, CategoryName, Verbosity, Format, ...) which might fit the bill. It’s conditional logging though, so you are still going to need a check of some sort.

What I do for loops when debugging is this:

GEngine->AddOnScreenDebugMessage(1, 1.0f, FColor::Green, FString::Printf(TEXT("Triggered")));

I’m not sure if you already knew, but the first parameter, if a positive number, sets the row for this message to appear in, so it will overwrite the message of the previous frame and not fill up the screen with log messages.

2 Likes

UE_LOG_ONLINE_ONCE does what you want.

1 Like

FYI I created a couple of macros in my helpers lib to do this: StevesUEHelpers/Source/StevesUEHelpers/Public/StevesLogHelpers.h at master · sinbad/StevesUEHelpers · GitHub

STEVES_LOG_ONCElogs once ever per session, much like the previously suggested UE_LOG_ONLINE_ONCEexcept that it lets you use your own category.

STEVES_LOG_NOREPEATis a bit smarter in that you can give it a type/value and it will only log if the value you pass it is different to the last time it was logged. This is more useful because it’ll expose multiple cases of a warning/error so long as it’s not warning about the same thing (sequentially). Very useful for code you call a lot in sequence and only want to be warned once until the value in question changes.