How to implement a virtual UFUNCTION?

You have various options:

  1. BlueprintNativeEvent, this is a function that has a base implementation on C++ and can be overridden in blueprints, in C++ you define the “_Implementation” one, you have to call the one that doesn’t end in “_Implementation” in C++
UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void RemoveNegativeAlteredStates();
void RemoveNegativeAlteredStates_Implementation();

If it’s overridden in blueprints and you want to call the base functionality as well, you have to “add call to parent function” by right clicking the function node, if you’re not going to override it in child C++ classes, you can omit the “_Implementation” declaration, you do have to define it though.

If you have to override the base C++ functionality in C++ child classes, you have to add the virtual modifier to the “_Implementation” declaration, like this:

UFUNCTION(BlueprintCallable, BlueprintNativeEvent)
void RemoveNegativeAlteredStates();
virtual void RemoveNegativeAlteredStates_Implementation();

You can’t omit the “_Implementation” declaration in this case.

  1. BlueprintImplementableEvent, same as above, but it doesn’t have a base implementation in C++:
UFUNCTION(BlueprintCallable, BlueprintImplementableEvent)
void RemoveNegativeAlteredStates();

You can do other stuff like what the previous poster suggested

A pretty good video I found on the topic is this one: UE4 - Blueprints to C++ Episode 3 - UFUNCTION - YouTube

I also recommend you sift through the specifiers for the different macros, benui has a pretty good compendium and documentation (at least, it’s more complete than the official one), I haven’t found that info on the community wiki: Unreal Engine Documentation · ben🌱ui

I think there are some caveats when using the RPC specifiers though, if you only need local calling of the function (like in the example you provided), I would go for the blueprint implementable event

3 Likes