BlueprintNativeEvents cannot be made virtual, an error message suggests otherwise

  1. Create a class. Doesn’t particularly matter what type of class, as long as it can have UFUNCTIONs defined inside of it.
  2. Define a UFUNCTION(BlueprintImplementableEvent) virtual void DoAThing();
  3. This fails, with an error message suggesting that you should use BlueprintNativeEvent instead. Change it to BlueprintNativeEvent.
  4. This fails, with an error message stating that BlueprintNativeEvents can’t be virtual.

This means they can’t be overridden in C++, unless Unreal does some seriously stupid language hacking, in which case this should be documented, but here are the entirety of the docs pages on BlueprintNativeEvent:

This function is designed to be overridden by a Blueprint, but also has a native implementation. Provide a body named [FunctionName]_Implementation instead of [FunctionName]; the autogenerated code will include a thunk that calls the implementation method when necessary.

and BlueprintImplementableEvent:

The function can be overridden in a Blueprint or Level Blueprint graph.

Nothing about virtual not being necessary to make it overrideable in C++, nothing about any way to do both… just nothing.

So, in short, either the error messages are misleading – which is a bug, hence this being a bug report – or the documentation needs to be updated – which I’m considering a bug so I don’t need to file this in two separate places, which would probably just be irritating for everyone. Either that or I’m missing some annotation which allows a method to be overridden in both C++ and Blueprints, without having to make separate, extra methods to wrap both and do some fancy logic of my own, since the only reason I’m using Unreal instead of writing everything from scratch is to get that kind of repetitive stuff taken care of for me.

Hey nic-hartley-

If I understand correctly you are trying to create a function that can both be overridden in a class blueprint as well as a child C++ class, correct? This is possible with the BlueprintNativeEvent specifier and _Implementation functions. Consider the following declaration:

UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = test)
	void TestFunction();

void TestFunction_Implementation();

The BlueprintNativeEvent is what allows the function to be overridden in blueprints and the _Implementation is the default code that is called if it is not overridden in blueprints. To be able to override this in your child class, you will need to make the _Implementation() function virtual ( virtual void TestFunction_Implementation();). In your child class you would have:

UFUNCTION(BlueprintCallable, BlueprintNativeEvent, Category = test)
void TestFunction();
    
virtual void TestFunction_Implementation() override;

This would allow you to implement the function both in your parent and child C++ class, and override them (independently) in their respective blueprints.

Cheers

4 Likes

5 years later and this solved my issue in UE5! Didn’t realize only the default implementation function needed to be virtual rather than both. Thanks !

Thanks, this helped a lot!