How to set Debug Actor in Gameplay Debugger?

In GameplayDebuggerCategory.cpp, there is the function:
void FGameplayDebuggerCategory::CollectData(APlayerController OwnerPC, AActor* DebugActor)*

From what I understand, the DebugActor is the currently selected actor in-editor; whether it’s the actor the player/camera is looking at when enabling the Gameplay Debugger with the (’) apostrophe key, or if the player un-possesses and selects their player character.

What I would like to know: Is there a way to select the currently possessed pawn/character as the DebugActor without having to unpossess and select the actual actor in-game before displaying the Gameplay Debugger?

It is mildly inconvenient to take the extra steps to unpossess, select my character, and then activate the GameplayDebugger in order to view the data that I want. Instead I would like to have the Gameplay Debugger either automatically use my possessed player as the DebugActor, or have the ability to bind a key, such as Enter, to toggle my possessed character as the DebugActor.

Any help would be appreciated, thanks.

1 Like

Yeah it would be nice to just select possessed pawn if there’s no valid debug actor in view.
I too would like to know the answer to this.

Unfortunately the only way I got it to work was by changing the engine code. But it works perfectly. In GameplayDebuggerLocalController::OnSelectActorTick(), right before it checks if the new debug actor is the same, check if BestCandidate is null, if so I put BestCandidate = OwnerPC->GetPawn(); since we want to default back to the owning player controller’s controlled pawn if it didn’t find a debug actor.

You’ll only be able to do this if you’ve your own compiled version of the engine, however.

None of the functions were virtual, so they can’t be overridden by child classes, otherwise that would have been a good answer too.

@RaptagonStudios, thanks so much for a response. Luckily, I do have my own compiled version and access to the engine code. I will try this out later this week and follow-up.

I was able to get the answer I needed, thanks to the suggestion made by Raptagon Studios. Here is what I did:

  1. Created a new gameplay debugger extension class and binded enter to it with:

//This is required so that the extension has the appropriate key used to handle it.
const FGameplayDebuggerInputHandlerConfig KeyConfig(TEXT(“Enter”), EKeys::Enter.GetFName());
bHasInputBinding = BindKeyPress(KeyConfig, this, &FHeroExtension_CharacterSelection::TogglePlayerSelect);

  1. In the extension class you have access to AGameplayDebuggerCategoryReplicator with the GetReplicator() function.

AGameplayDebuggerCategoryReplicator* Replicator = GetReplicator();

  1. You can then use the replicator to access both GetDebugActor() and SetDebugActor()

This is the final segment of code I used:

void FHeroExtension_CharacterSelection::TogglePlayerSelect()
{
	//Gets Replicator and updates the current debug actor based on whether there is already a valid selected player or not.
	AGameplayDebuggerCategoryReplicator* Replicator = GetReplicator();
	if (Replicator)
	{
		class AHeroCharacter* Character = SelectedPlayer.Get();
		class AActor* SelectedActor = InitialActor.Get();
		if (Character)
		{
			Replicator->SetDebugActor(SelectedActor, false);
			SelectedPlayer = nullptr;
		}
		else
		{
			APlayerController* OwnerPC = GetPlayerController();
			if (OwnerPC)
			{
				Character = Cast<AHeroCharacter>(OwnerPC->GetCharacter());
				SelectedPlayer = Character;
				Replicator->SetDebugActor(Character, false);
			}
		}
	}

	bIsCachedDescriptionValid = false;
}

I really hope this helps somebody in the future :smiley: Thanks again for the help.

3 Likes