How do i expose a C++ Interface to Blueprints with a BlueprintCallable function?
Hello i have an interface that is implemented by some of my c++ classes, and each one overrides a function that returns it's own value for each class. The problem is that i want to expose the interface to blueprints (by using UINTERFACE(Blueprintable)) and i just want to call that function in blueprints, but the compiler doesn't allow me to have BlueprintCallable modifiers in Blueprintable interfaces, only BlueprintImplementableEvent is allowed (which i don't want). What else can i do to make this work? Thank you.
asked Dec 21 '15 at 04:11 PM in C++ Programming
I've faced this issue before. What works is to use both BlueprintNativeEvent and BlueprintCallable together while declaring your interface function. This optionally allows you to override it in BP as well, but in your case you don't need to as you're just interested in calling the function. Like this:
Be sure to use this specific format to declare the function in whichever C++ class is implementing it:
This is necessary because the generated code behind the scenes is declared in this manner. Implement this function in your CPP with the this name too (i.e. _Implementation needs to be appended to the function name).
This should work fine - I just setup an interface like this now for my own work and I'm able to call it from Blueprints.
PS: Some additional information that may help down the line - if you do decide to implement your interface function in a Blueprint you might need to use the syntax Execute_SomeInterfaceFunction(UObject* YourObject) to call those interface functions from C++.
[UPDATE - 12th Jan 2016]
I just stumbled upon some of my old project code that does exactly what you ask for even without needing BlueprintNativeEvent. Looks like marking the interface as CannotImplementInterfaceInBlueprint is key.
Here's an example (dummy names):
Follow this question
Once you sign in you will be able to subscribe for any updates here