I have this IInterface (and matching UInterface), but both ShowOverlay and ShowMenu are shown in blueprints as events I can subscribe to rather than functions I can overwrite. What do I need to do to get overwritable functions?
// In the interface .h - declare as
UFUNCTION(BlueprintNativeEvent, Category = "UI") // ...instead. Will appear in BP editor under "Interfaces" heading in MyBlueprint settings.
// In some implementing class .h, optionally provide a native implementation (and/or BP can override)
virtual void SomeClass::ShowOverlay_Implementation(UUserWidget* MessageWidget) override;
...
Yeah void functions always show up in blueprints as events. It doesn’t constrain you in any way - just add your override from the event node instead of in a function.
There is one constraint I found:
If you are passing an input by reference, event will not be able to modify the original input while function can. This happened for a USTRUCT for me, so i am not sure how widely applicable this is.
UE5 did notify me that “no value will be returned by reference” when using the event. Adding a dummy output to the interface fixed it.
This is such a frustrating answer. It just answer what without the much more important why. Functions and events are two quite distinct thing, so it seems crazy I can’t just implement C++ function and then override it in BP as a function, not as an event, without some distasteful dummy return value.
Because in blueprint the event graph is more useful than functions a lot of the time. They can use latent functions when function can’t.
They aren’t really two different things, they just exist in slightly two different spaces in the blueprint.
Good new is that you don’t have to add a dummy return value. At least not anymore, the ForceAsFunction UFUNCTION meta tag will for the event to be created as a function instead of as an event.
Also you can right click on functions or events to swap them to be the other thing now. So even it an event is initially created as an event (and you can’t/shouldn’t change the source to add the tag) you can still swap it in your implementation to be the thing you want it to be.