Language:
Page Info
Engine Version:

Functions

Choose your OS:

Function Declaration

Functions can exist in two basic forms: a regular C++ function or a UFunction. Both C++ functions and UFunctions are declared in the .h class header file. C++ functions are declared using the standard C++ syntax for declaring a function. UFunctions use a specialized syntax that allows additional information about the function to be specified in the declaration through the use of Function Specifiers .

UFUNCTION([specifier, specifier, ...], [meta(key=value, key=value, ...)])
ReturnType FunctionName([Parameter, Parameter, ...])

UFunctions behave the same as C++ functions in that they have a C++ implementation, can be called from within C++ code, and can contain calls to other C++ functions or UFunctions within their function bodies. UFunctions differ in a few areas, however. For instance, they can be called or overridden from within the Blueprint Visual Scripting system. Any UFunction declared using the BlueprintCallable, BlueprintImplementableEvent, or BlueprintPure specifiers (see Function Specifiers below for more details) will be exposed to Blueprints. UFunctions can also be assigned as delegates within the default properties of a class. This technique is commonly used to bind input actions or axes to functions in Input classes. UFunctions are also used as replication callbacks; meaning the UFunction will be called when the variable it is associated with changes and is replicated across the network. UFunctions are also the only type of function that can be declared as an exec function allowing them to be called by the player from the in-game console during play.

Function Specifiers

When declaring functions, specifiers can be added to the declaration to control how the function behaves with various aspects of the engine and editor.

Function Specifier

Effect

BlueprintAuthorityOnly

This function will only execute from Blueprint code if running on a machine with network authority (a server, dedicated server, or single-player game).

BlueprintCallable

The function can be executed in a Blueprint or Level Blueprint graph.

BlueprintCosmetic

This function is cosmetic and will not run on dedicated servers.

BlueprintGetter

This function will be used as the accessor for a Blueprint-exposed property. This specifier implies BlueprintPure and BlueprintCallable.

BlueprintImplementableEvent

The function can be implemented in a Blueprint or Level Blueprint graph.

BlueprintInternalUseOnly

Indicates that the function should not be exposed to the end user.

BlueprintNativeEvent

This function is designed to be overridden by a Blueprint, but also has a default native implementation. Declares an additional function named the same as the main function, but with _Implementation added to the end, which is where code should be written. The autogenerated code will call the "_Implementation" method if no Blueprint override is found.

BlueprintPure

The function does not affect the owning object in any way and can be executed in a Blueprint or Level Blueprint graph.

BlueprintSetter

This function will be used as the mutator for a Blueprint-exposed property. This specifier implies BlueprintCallable.

CallInEditor

This function can be called in the editor on selected instances via a button in the details panel.

Category = TopCategory|SubCategory|Etc

Specifies the category of the function when displayed in Blueprint editing tools. Define nested categories using the | operator.

Client

The function is only executed on the client that owns the Object on which the function is called. Declares an additional function named the same as the main function, but with _Implementation added to the end. The autogenerated code will call the "_Implementation" method when necessary.

CustomThunk

The UnrealHeaderTool code generator will not produce a thunk for this function; it is up to the user to provide one.

Exec

The function can be executed from the in-game console. Exec commands only function when declared within certain classes.

NetMulticast

The function is both executed locally on the server and replicated to all clients, regardless of the Actor's NetOwner.

Reliable

The function is replicated over the network, and is guaranteed to arrive regardless of bandwidth or network errors. Only valid when used in conjunction with Client or Server.

SealedEvent

This function cannot be overridden in subclasses. The SealedEvent keyword can only be used for events. For non-event functions, declare them as static or final to seal them.

ServiceRequest

This function is an RPC service request.

ServiceResponse

This function is an RPC service response.

Server

The function is only executed on the server. Declares an additional function named the same as the main function, but with _Implementation added to the end, which is where code should be written. The autogenerated code will call the "_Implementation" method when necessary.

Unreliable

The function is replicated over the network but can fail due to bandwidth limitations or network errors. Only valid when used in conjunction with Client or Server.

WithValidation

Declares an additional function named the same as the main function, but with _Validation added to the end. This function takes the same parameters, and returns a bool to indicate whether or not the call to the main function should proceed.

Metadata Specifiers

The usage of metadata specifiers differs between regular classes, functions, and interfaces.

Function Meta Tag

Effect

AdvancedDisplay="Parameter1, Parameter2, .."

The comma-separated list of parameters will show up as advanced pins (requiring UI expansion).

AdvancedDisplay=N

Replace N with a number, and all parameters after the Nth will show up as advanced pins (requiring UI expansion). E.g. 'AdvancedDisplay=2' will mark all but the first two parameters as advanced).

ArrayParm="Parameter1, Parameter2, .."

Indicates that a BlueprintCallable function should use a Call Array Function node and that the listed parameters should be treated as wild card array properties.

ArrayTypeDependentParams="Parameter"

When ArrayParm is used, this specifier indicates one parameter which will determine the types of all parameters in the ArrayParm list.

AutoCreateRefTerm="Parameter1, Parameter2, .."

The listed parameters, although passed by reference, will have an automatically-created default if their pins are left disconnected. This is a convenience feature for Blueprints.

BlueprintAutocast

Used only by static BlueprintPure functions from a Blueprint Function Library. A Cast node will be automatically added for the return type and the type of the first parameter of the function.

BlueprintInternalUseOnly

This function is an internal implementation detail, used to implement another function or node. It is never directly exposed in a Blueprint Graph.

BlueprintProtected

This function can only be called on the owning Object in a Blueprint. It cannot be called on another instance.

CallableWithoutWorldContext

Used for BlueprintCallable functions that have a WorldContext pin to indicate that the function can be called even if its class does not implement the GetWorld function.

CommutativeAssociativeBinaryOperator

Indicates that a BlueprintCallable function should use the Commutative Associative Binary node. This node lacks pin names, but features an "Add Pin" button that creates additional input pins.

CompactNodeTitle="Name"

Indicates that a BlueprintCallable function should display in the compact display mode, and provides the name to display in that mode.

CustomStructureParam="Parameter1, Parameter2, ..")

The listed parameters are all treated as wildcards. This specifier requires the UFUNCTION-level specifier, CustomThunk, which will require the user to provide a custom exec function. In this function, the parameter types can be checked and the appropriate function calls can be made based on those parameter types. The base UFUNCTION should never be called, and should assert or log an error if it is.

DefaultToSelf

For BlueprintCallable functions, this indicates that the Object property's named default value should be the self context of the node.

DeprecatedFunction

Any Blueprint references to this function will cause compilation warnings telling the user that the function is deprecated. You can add to the deprecation warning message (e.g. to provide instructions on replacing the deprecated function) using the DeprecationMessage metadata specifier.

DeprecationMessage="Message Text"

If the function is deprecated, this message will be added to the standard deprecation warning when trying to compile a Blueprint that uses it.

DisplayName="Blueprint Node Name"

The name of this node in a Blueprint will be replaced with the value provided here, instead of the code-generated name.

ExpandEnumAsExecs="Parameter"

For BlueprintCallable functions, this indicates that one input execution pin should be created for each entry in the enum used by the parameter. That the named parameter must be of an enumerated type recognized by the Engine via the UENUM tag.

HidePin="Parameter"

For BlueprintCallable functions, this indicates that the parameter pin should be hidden from the user's view. Note that only one parameter pin per function can be hidden in this manner.

KeyWords="Set Of Keywords"

Specifies a set of keywords that can be used when searching for this function, such as when placing a node to call the function in a Blueprint Graph.

Latent

Indicates a latent action. Latent actions have one parameter of type FLatentActionInfo, and this parameter is named by the LatentInfo specifier.

LatentInfo="Parameter"

For Latent BlueprintCallable functions indicates which parameter is the LatentInfo parameter.

MaterialParameterCollectionFunction

For BlueprintCallable functions, indicates that the material override node should be used.

NativeBreakFunc

For BlueprintCallable functions, indicates that the function should be displayed the same way as a standard Break Struct node.

NotBlueprintThreadSafe

Only valid in Blueprint Function Libraries. This function will be treated as an exception to the owning class's general BlueprintThreadSafe metadata.

ShortToolTip

A short tooltip that is used in some contexts where the full tooltip might be overwhelming, such as the parent class picker dialog.

ToolTip

Overrides the automatically generated tooltip from code comments.

UnsafeDuringActorConstruction

This function is not safe to call during Actor construction.

WorldContext="Parameter"

Used by BlueprintCallable functions to indicate which parameter determines the World that the operation is occurring within.

Function Parameter Specifiers

Out
Optional

Function Implementations

Functions declared in the class header file are given definitions in the class source file.

Delegates

Delegates allow you to call member functions on C++ objects in a generic, yet type-safe way. Using delegates, you can dynamically bind to a member function of an arbitrary object, then call functions on the object, even if the caller does not know the object's type.

It is perfectly safe to copy delegate objects. Delegates can be passed around by value but this is generally not recommended since they do have to allocate memory on the heap. You should always pass delegates by reference when possible.

Both single-cast and multi-cast delegates are supported, as well as "dynamic" delegates which can be safely serialized to disk.

See the Delegates page for reference and usage information.

Timers

Timers schedule actions to be performed after a delay, or at a over a period of time. For example, you may want to make the player invulnerable after obtaining a power-up item, and then restore vulnerability after 10 seconds. Or, you may want to apply damage once per second while the player moves through a room filled with toxic gas. Each of these can be achieved through the use of timers.

See the Gameplay Timers page for reference and usage information.