UFunction Declaration
A UFunction is a C++ function that is recognized by the Unreal Engine reflection system. Any UObject
or Blueprint function library can declare a member function as a UFunction by placing the UFUNCTION
macro on the line above the function declaration in the header file. The macro will support Function Specifiers to change how Unreal Engine interprets and uses a function.
UFUNCTION([specifier1=setting1, specifier2, ...], [meta(key1="value1", key2, ...)])
ReturnType FunctionName([Parameter1, Parameter2, ..., ParameterN1=DefaultValueN1, ParameterN2=DefaultValueN2]) [const];
With Function Specifiers, you can expose UFunctions to Blueprint Visual Scripting graphs, which provide a way for developers to call or extend UFunctions from Blueprint Assets without having to alter C++ code.
UFunctions are able to bind to Delegates in the default properties of a Class, enabling them to perform such tasks as associating actions with user inputs. They can also act as network callbacks, meaning you can use them to receive a notification and run custom code whenever a certain variable is affected by a network update.
You can even create your own console commands (often called debug, configuration, or cheat code commands) that you can call from the game console in development builds, or add buttons with custom functionality to game objects in the Level Editor.
Function Specifiers
When declaring functions, Function Specifiers can be added to the declaration to control how the function behaves with various aspects of the engine and the editor.
Function Specifier |
Effect |
---|---|
|
This function will only execute from Blueprint code if running on a machine with network authority (a server, dedicated server, or single-player game). |
|
The function can be executed in a Blueprint or Level Blueprint graph. |
|
This function is cosmetic and will not run on dedicated servers. |
|
The function can be implemented in a Blueprint or Level Blueprint graph. |
|
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 |
|
The function does not affect the owning object in any way and can be executed in a Blueprint or Level Blueprint graph. By default functions that are marked
|
|
This function can be called in the editor on selected instances via a button in the Details panel. |
|
Specifies the category of the function when displayed in Blueprint editing tools. Define nested categories using the | operator. |
|
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 |
|
The |
|
The function can be executed from the in-game console. Exec commands only function when declared within certain Classes. |
|
The function is executed both locally on the server, and replicated to all clients, regardless of the Actor's |
|
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 |
|
This function cannot be overridden in subclasses. The |
|
This function is an RPC (Remote Procedure Call) service request. This implies |
|
This function is an RPC service response. This implies |
|
The function is only executed on the server. Declares an additional function named the same as the main function, but with |
|
The function is replicated over the network but can fail due to bandwidth limitations or network errors. Only valid when used in conjunction with |
|
Declares an additional function named the same as the main function, but with |
Metadata Specifiers
When declaring classes, interfaces, structs, enums, enum values, functions, or properties, you can add Metadata Specifiers to control how they interact with various aspects of the engine and editor. Each type of data structure or member has its own list of Metadata Specifiers.
Metadata only exists in the editor; do not write game logic that accesses metadata.
Function Meta Tag |
Effect |
---|---|
|
The comma-separated list of parameters will show up as advanced pins (requiring UI expansion). |
|
Replace |
|
Indicates that a |
|
When |
|
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, often used on array pins. |
|
Used only by static |
|
This function is an internal implementation detail, used to implement another function or node. It is never directly exposed in a Blueprint graph. |
|
This function can only be called on the owning Object in a Blueprint. It cannot be called on another instance. |
|
Used for |
|
Indicates that a |
|
Indicates that a |
|
The listed parameters are all treated as wildcards. This specifier requires the To declare a custom |
|
For |
|
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 (for example, to provide instructions on replacing the deprecated function) using the |
|
If the function is deprecated, this message will be added to the standard deprecation warning when trying to compile a Blueprint that uses it. |
|
The return type of the function will dynamically change to match the input that is connected to the named parameter pin. The parameter should be a templated type like |
|
Functions marked as |
|
The name of this node in a Blueprint will be replaced with the value provided here, instead of the code-generated name. |
|
For |
|
For |
|
Hides the "self" pin, which indicates the object on which the function is being called. The "self" pin is automatically hidden on |
|
Similar to |
|
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. |
|
Indicates a latent action. Latent actions have one parameter of type |
|
For Latent |
|
For |
|
For |
|
Only valid in Blueprint function libraries. This function will be treated as an exception to the owning Class's general |
|
A short tooltip that is used in some contexts where the full tooltip might be overwhelming, such as the Parent Class Picker dialog. |
|
Overrides the automatically generated tooltip from code comments. |
|
This function is not safe to call during Actor construction. |
|
Used by |
Function Parameter Specifiers
Parameter Specifier |
Description |
---|---|
Out |
Declares the parameter as being passed by reference, allowing it to be modified by the function. |
Optional |
With the optional keyword, you can make certain function parameters optional, as a convenience to the caller. The values for optional parameters which the caller does not specify depend on the function. For example, the |
Delegates
Delegates can call member functions on C++ objects in a generic, type-safe way. A delegate can be bound dynamically to a member function of an arbitrary object, calling the function on the object at a future time, even if the caller does not know the object`s type.
See the Delegates page for reference and usage information.
Timers
Timers schedule actions to be performed after a delay, or over a period of time. For example, you may want to make the player invulnerable after obtaining a power-up item, 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. Such actions can be achieved through the use of timers.
See the Gameplay Timers page for reference and usage information.