Debug Enhanced Input fails without a Pawn

in 5.7 the assumption to use the first local player’s enhanced input subsystem for debug was removed by getting the targeted pawn from the HUD. This expansion in functionality is very welcome but perhaps has introduced a regression, we used the enhanced input debug in our frontend - where we have no pawn.

I’m wondering if there’s a different tool that we should use in this scenario or if falling back to the old behaviour is a reasonable expectation.

		if (HUD->ShouldDisplayDebug(NAME_EnhancedInput))
		{
			FDisplayDebugManager& DisplayDebugManager = Canvas->DisplayDebugManager;
			DisplayDebugManager.SetFont(GEngine->GetSmallFont());
			DisplayDebugManager.SetDrawColor(FColor::Yellow);
			DisplayDebugManager.DrawString(TEXT("ENHANCED INPUT"));

			bool bFoundValidDebugTarget = false;
			// Checking if the debug target actor is a valid local player, if so then show their debug info
			// If target actor is not a local player then don't display anything
			if (APawn* TargetPawn = Cast<APawn>(HUD->GetCurrentDebugTargetActor()))
			{
				if (APlayerController* PlayerController = Cast<APlayerController>(TargetPawn->GetController()))
				{
					if (const ULocalPlayer* LocalPlayer = Cast<ULocalPlayer>(PlayerController->Player))
					{
						if (UEnhancedInputLocalPlayerSubsystem* EnhancedInputSubsystem = ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(LocalPlayer))
						{
							EnhancedInputSubsystem->ShowDebugInfo(Canvas);
							bFoundValidDebugTarget = true;
						}
					}
				}
			}

			if(!bFoundValidDebugTarget)
			{ 
				DisplayDebugManager.SetDrawColor(FColor::Red);
				DisplayDebugManager.DrawString(TEXT("Debug Target is not valid for Enhanced Input Debug Display"));
 
//begin - fallback to the old behaviour if we can't find the subsystem
				TObjectIterator<UEnhancedInputLocalPlayerSubsystem> FirstPlayer;
				if (FirstPlayer)
				{
					FirstPlayer->ShowDebugInfo(Canvas);
				}
//end - fallback to the old behaviour if we can't find the subsystem
			}
		}


Looking forwards to your advice in this matter.

[Attachment Removed]

Steps to Reproduce
Not sure if repro steps are required.

[Attachment Removed]

Would it also be possible to use something like this to solve it more generally?

const APlayerController* HUDOwner = HUD->GetOwningPlayerController();
const ULocalPlayer* HUDLocalPlayer = HUDOwner ? Cast<ULocalPlayer>(HUDOwner->Player) : nullptr;
if (UEnhancedInputLocalPlayerSubsystem* EnhancedInputSubsystem =
        HUDLocalPlayer ? ULocalPlayer::GetSubsystem<UEnhancedInputLocalPlayerSubsystem>(HUDLocalPlayer) : nullptr)
{
    EnhancedInputSubsystem->ShowDebugInfo(Canvas);
}

[Attachment Removed]

Hi,

This should be resolved now, the approach is pretty similar to your latest comment. You’ll have to backport from the UE6 branch, but take a look at CL#55739416 if you want to cherrypick the fix.

Best,

Cody

[Attachment Removed]