Named Arguments
Last updated
Last updated
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.
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.
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.
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.
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 section for more details.
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 .