Functions and BlueprintEvents🔗
Plain Script Functions🔗
Functions can be declared as methods in a class or globally. By default any function you declare can only be called from script and is not accessible to blueprint.
Functions that can be called from Blueprint🔗
To make it so a function can be called from blueprint, add a UFUNCTION()
specifier above it.
Note: Unlike in C++, it is not necessary to specify
BlueprintCallable
, it is assumed by default.
Overriding BlueprintEvents from C++🔗
To override a Blueprint Event declared from a C++ parent class, use the BlueprintOverride
specifier.
You will use this often to override common events such as BeginPlay
or Tick
:
The visual studio code extension has helpers for easily overriding blueprint events from parent classes.
When the cursor is within a class, you can click the Lightbulb icon (or press Ctrl + . by default) to choose a function to override:
Typing the name of an overridable event also suggests a completion for the full function signature:
Note: For C++ functions that don't explicitly specify a
ScriptName
meta tag, some name simplification is automatically done to remove common prefixes.
For example, the C++ event is calledReceiveBeginPlay
, but the preceedingReceive
is removed and it just becomesBeginPlay
in script.
Other prefixes that are removed automatically areBP_
,K2_
andReceived_
.
Overriding a Script Function from Blueprint🔗
Often you will want to create a blueprint that inherits from a script parent class.
In order to make a function so it can be overridden from a child blueprint, add the BlueprintEvent
specifier.
Note: Script has no split between
BlueprintImplementableEvent
andBlueprintNativeEvent
like C++ has. All script functions require a base implementation, although it can be left empty.
Tip: Separate Blueprint Events🔗
One pattern that is employed often in Unreal is to have separate base and blueprint events. This way you can guarantee that the script code always runs in addition to nodes in the child blueprint, and you will never run into issues if the blueprint hasn't done "Add call to parent function".
For example, a pickup actor might do:
Global Functions🔗
Any script function in global scope can also have UFUNCTION()
added to it.
It will then be available to be called from any blueprint like a static function.
This lets you create functions not bound to a class, similar to how Blueprint Function Libraries work.
Tip: Comments above function declarations become tooltips in blueprint, just like in C++
Calling Super Methods🔗
When overriding a script function with another script function, you can use the same Super::
syntax from Unreal C++ to call the parent function.
Note that script methods can be overridden without needing BlueprintEvent
on the base function (all script methods are virtual). However, when overriding a BlueprintEvent
, you will need to specify BlueprintOverride
on the overrides.
Note: When overriding a C++
BlueprintNativeEvent
, it is not possible to call the C++ Super method due to a technical limitation. You can either prefer creatingBlueprintImplementEvent
s, or put the base implementation in a separate callable function.