Global Blueprint-Callable C++ Functions?

Hi, can someone please explain how to create a global (not any class’ member function) function in C++ and make it available in blueprint graphs? I checked the documentation about blueprint functions, but it’s only dealing with implementations inside an actor-class.

What I need is my own version of “ApplyDamage”, because I’m beginning to think that the UE4 implementation is rather bad, especially when it comes to using UDamageType.

I only use blueprints at the end of my class-hierarchies, because I find them useful for setting up references and other defaults as well. I still want to at least be able to trigger damage events via blueprint.

This is what you want: Blueprint Function Libraries | Unreal Engine Documentation

Create a class derived from UBlueprintFunctionLibrary and create a static function like this:

UFUNCTION(BlueprintCallable, Category = "CustomDamage")
static void ApplyDamage(UDamageType* Type, float Damage, AActor* Receiver);

This function will now be globally visible for all blueprints. Note that for some functions you may need a UWorld object e.g. for spawning or game state information. While you could pass in a valid UObject all the time it can be more comfortable to just use the calling object as a world context object. This way you can drop the Context Object pin.

UFUNCTION(BlueprintCallable, Category = "Category", meta = (HidePin = "WorldContextObject", DefaultToSelf = "WorldContextObject"))
		static void DoSomething(UObject* WorldContextObject);

The node of this function won’t show the WorldContextObject as a pin but will always default to the calling object as WorldContextObject. Just fyi

1 Like