How can I use UFUNCTION(Exec) from within UActorComponent?

Hello!–

I am trying to enable a debug flag on my component using the Console

I am able to see my function by flagging it as EXEC, however it does not execute when run.

  • I attempted both a static and non-static implementation of my function with no success

Any solutions or work-arounds would be greatly appreciated.

Thanks in advance :slight_smile:


For Devs: If possible, I would also like to request further Documentation on the Exec feature. The doc states it only works in some classes, but that information is unavailable so far as I can tell.

Hi JDizzleSTiX,

I spoke with a member of our Documentation team, and they confirmed that the page for the Exec function specifier is one that they have targeted for improvement. They were also able to provide me with a list of classes that look for exec functions, and those classes are: Pawn, PlayerController, CheatManager, GameMode, PlayerInput, and HUD. I do not have any information regarding what you can try to do as a work around for this. Would you be able to provide more details regarding exactly what end result you are looking for, and how you are currently trying to achieve that (some code snippets would be great)?

Thanks,

That doesnt work by default, you’d have to hook it up yourself. To do so you could override ProcessConsoleExec on your player pawn to forward it to your component (just find the components you want and call ProcessConsoleExec on them if the super returns false

Thank you for the response, ! Love hearing that the team is looking into improving this.


Code snippets would be simple here. Imagine defining a Component variable (static or non-static) that an Exec function can set to true/false. As an example: a variable that enables debug drawing to visualize a frontal perception cone of an AActor.


It may be more worthwhile to explain what I am trying to achieve.

I am investigating the creation of a standalone Plugin with multiple Modules…

…responsible for various UActorComponents and their associated UObjects/Data. The goal is to conveniently attach these to any Actor within any given Project. Each component then has their own self-contained debug to visualize parameters and output on the owning AActor.

The scenario I am trying to avoid is…

…needing to create an additional module that includes my whole Plugin and implements a CheatManager/Pawn/GameMode where all the debug functionality must reside and all Projects must inherit from.

  • In general, I hope to keep my modules separate and only include one-another when functionality between one-another is required.
  • I am worried that if the debug is not within the Component, I will need to provide various methods for private/protected data that the debug content must access.

That all said, recommendations would be greatly appreciated if you feel this may be the wrong path. I would love to hear how a Staffer would approach a solution to this :slight_smile:

Thanks in advance!
J

Thanks, ! I will give this a shot.

Fingers cross that I can just shoot them at all the Components and see which one will handle it.

I can now confirm that this does work:

added to my PlayerController .h file:

virtual bool ProcessConsoleExec(const TCHAR* Cmd, FOutputDevice& Ar, UObject* Executor) OVERRIDE;

added to my PlayerController .cpp file:

bool AMyPlayerController::ProcessConsoleExec(const TCHAR* Cmd, FOutputDevice& Ar, UObject* Executor)
{
	bool Result = false;
	APawn* const Pawn = GetPawn();
	TArray<UActorComponent*> Components;
	Pawn->GetComponents<UActorComponent>(Components);
	for (UActorComponent* Comp : Components)
	{
		Result = Comp->ProcessConsoleExec(Cmd, Ar, Executor) || Result;
	}
	return Result;
}