Blueprint Function Library

From Unreal Wiki
Revision as of 17:46, 20 March 2025 by Unreal583 (talk | contribs)
Jump to navigation Jump to search


Blueprint Function Libraries

Blueprint Function Libraries(BPL) are static libraries that can be used over and over, the word static in this context means, that only<br?

one instance of the object/library/class exists.

Take Components for example, for a while I was using Components as function libraries and would attach them to a Actor if I needed those functions
however this would take up unnecessary memory and space as each instance of the Component would need to exist.
This is also not optimal or correct usage, Components should be used when you need to store specific information such as Inventory
Whereas a function library should be used when no storage or specific identity is needed (such as string handling functions or mathematic operations)

Blueprint Blueprint Function Libraries

Right click the content drawer and select Blueprint->Blueprint Function library

When you make a function in the library you can then call it from any class globally.
For example if a I make a function "Print String Test"

I can then use it in my BP_ThirdPersonCharacter blueprint by right clicking the event graph (or in any graph) In selecting Print String Test

C++ Blueprint Function Libaries

When can also achieve the same results in c++ by adding a new c++ class, and inheriting from the
Blueprint Function Library

Inside our newly created class, we can see that we inherit from UBlueprintFunctionLibrary, from here we can make a UFUNCTION(BlueprintCallable) as normal and make sure the function
is static a Complete example is below
TO DO: syntax highlight

UCLASS()

class UCP_BPL : public UBlueprintFunctionLibrary

{

GENERATED_BODY()


UFUNCTION(BlueprintCallable, Category="CP_BPL")

static void CP_PrintTestString()

{

GEngine->AddOnScreenDebugMessage(-1, 5, FColor::Red, "CP_PrintTestString");

}


};