Here is some collection of non (yet) sorted tips and tricks I want to share with you. Not only found by me, but thanks to a lot of people around.

DrawDebugString limit

One day friend said me:

i am debugging and debugging for 3 hours straight where my algorithm fails
for debugging i use DrawDebugString()
and i was always wondering why not all strings i need are displayed in the world
APPARENTLY THE NUMBER OF DEBUG STRINGS IS CLAMPED

While I've never had this issue (thus I've never used more than ~10 strings simultaneously), I was quite curious what is going on. DrawDebugString actually calls PlayerController->MyHUD->AddDebugText which requires an Actor, but here is interesting thing. DrawDebugString has an Actor argument defaulted to nullptr. From the DrawDebugString code, Actor is chosen like that:

AActor* BaseAct = (TestBaseActor != nullptr) ? TestBaseActor : InWorld->GetWorldSettings();

so if you don't touch Actor arg, or specify nullptr, WorldSettings actor will be picked. And yes, there is a limit on how much texts you can use per one Actor. This is determined in AHUD::AddDebugText_Implementation

// if there's a max number per actor, respect it : 
int32 MaxNumStrings = GMaxDebugTextStringsPerActorCVar.GetValueOnGameThread();
if ((MaxNumStrings <= 0) || (NumElements < MaxNumStrings))
{
                DebugTextInfo = &DebugTextList.EmplaceAt_GetRef(LastIdx + 1);
}

and the limit is defined as:

TAutoConsoleVariable<int32> GMaxDebugTextStringsPerActorCVar(
    TEXT("r.DebugSafeZone.MaxDebugTextStringsPerActor"),
    128,
    TEXT("The maximum number of debug strings that can be attached to a given actor (<=0 : no limit)"));

This speaking, if you ever need to increase a limit of Debug Strings (and not using them per actor), you should set r.DebugSafeZone.MaxDebugTextStringsPerActor to desired limit value, or to <= 0 to disable the limit completely.

Previous Post