Named Arguments

Named arguments are parameters that get their values assigned at runtime by game code. They are usually set by Event Processors during action execution. Named arguments must always start with a dollar sign $ followed by the argument name.

Let's take a look at an example. The I/O system has built-in named arguments for some events, such as the "OnTriggerEnter" event of the TriggerBox actor. This event has a named argument called $Actor which will be a reference to the actor that entered the trigger.

Before the action is executed, the $Actor parameter will be replaced by the path of the actor that entered the trigger. The C++ reflection system is able to understand this path and turn it into an Actor Reference for the function to use.

Global Named Arguments

The I/O system also supports global named arguments which are not tied to any specific event, so they can be used for all actions. By default there is only one global named argument called $Player which is a reference to the local player's pawn.

Creating Named Arguments

As mentioned before, named arguments are always created before the action is executed. We can use an Event Processor to set named arguments for the action before it is executed.

An Event Processor is a function assigned to an I/O event. This function is always triggered before executing an action that is bound to the owning I/O event. The signature (parameter list) of this function should be exactly the same as the delegate that is assigned to the owning I/O event.

Let's say you have an event called OnPickup. You can create a new function and assign it as the event processor of the OnPickup event. Make sure that the parameter list of the function matches the delegate exactly. In my case this is a Blueprint event dispatcher with one variable for the pawn that picked up the item, so my event processor also has that one parameter.

This is all in the same actor blueprint.
void APickupActor::RegisterIOEvents(FActorIOEventList& EventRegistry)
{
	EventRegistry.RegisterEvent(FActorIOEvent()
		.SetId(TEXT("APickupActor::OnPickup"))
		.SetDisplayName(INVTEXT("OnPickup"))
		.SetTooltipText(INVTEXT("Event when the item is picked up."))
		.SetMulticastDelegate(this, &OnPickup)
		.SetEventProcessor(this, TEXT("ProcessEvent_OnPickup")));
}

Inside the event processor, simply use the SetNamedArgument function to add a new named argument to the current execution context. Notice that the value of the argument is still in string form, so it must be in the format that is understood by the I/O system and Unreal. See Function Parameters section for more details.

Arguments remain in string form up until the very end when the final command is sent to the target actor by the action, and the C++ reflection system parses the parameters.

void APickupActor::ProcessEvent_OnPickup(APawn* InstigatorPawn)
{
	FActionExecutionContext& ExecContext = FActionExecutionContext::Get(this);
	ExecContext.SetNamedArgument(TEXT("$Instigator"), InstigatorPawn->GetPathName());
}

Creating Global Named Arguments

To create global named arguments, use the same SetNamedArgument function, but instead of doing it from an event processor, override the GetGlobalNamedArguments function of the Actor I/O Subsystem.

Last updated