C++ UInterface must be const

Non-const functions are not implementable or callable from blueprints. In the definition below, only MyFunc is available to be implemented or called in blueprints, the other two functions don’t show up at all. Is this by design?


UINTERFACE(Blueprintable)
class UMyInterface : public UInterface
{
	GENERATED_UINTERFACE_BODY()
};

class IMyInterface
{
	GENERATED_IINTERFACE_BODY()

public:

	UFUNCTION(BlueprintImplementableEvent, Category = "Blah")
	void DoSomething(class MyClass* Blah);

	UFUNCTION(BlueprintImplementableEvent, Category = "Blah")
	void MyFunc() const;

	UFUNCTION(BlueprintNativeEvent, Category = "Blah")
	void MyFunc2();
};

Hi Greg,

Unfortunately, this is a common source of confusion.

Currently, there is a split between what we call “events” (which are implemented in the Blueprint Class Event Graph), and “functions” (which are implemented in their own Blueprint Class Function Graph).

Any non-const function tagged as ‘BlueprintImplementableEvent’ or ‘BlueprintNativeEvent’ is considered to be an “event” if the function has no return value and no output parameters. That is, the implementation will end up in the Event Graph. Everything else is a “function” and will be implemented in its own graph.

As a result, you do not see the ‘DoSomething’ and ‘MyFunc2’ functions in the My Blueprint panel in the “Interfaces” section because they are not currently seen as “functions” per se - this area currently shows a list of the unique Function Graphs that have been created for the non-event signatures in the implemented Interface. Since the interface above declares 2 “events,” those will not get their own Function Graphs, and thus won’t show up in that list.

You will find however that if you right-click in the Event Graph and type in ‘DoSomething’ and ‘MyFunc2’ in the context menu’s filter box, they should appear as “Interface Events” that can be placed as nodes in that graph (just like other events) and you can implement them there.

Now, to further complicate things a bit. =/

When you choose to implement an interface in the editor, as noted above, that automatically creates a Function Graph for all the non-event function signatures. As part of that, those functions are implicitly set to ‘BlueprintCallable’ so that they can be called from other events/functions. Sadly, however, this is not currently the case when you implement a native interface event in the Event Graph - that is, while you can implement the event via right-click context menu, you cannot also call it from the Blueprint side currently by default. In order to do that, you’ll need to explicitly add ‘BlueprintCallable’ to the UFUNCTION() markup in the native interface’s C++ header file for any event methods.

That’s a bit of an inconsistency with interfaces created inside the UE4 editor (i.e. non-native interfaces), as any function created there is also marked ‘BlueprintCallable’ by default. I’ve also entered an issue to track this for a potential consistency fix, reference# UE-21004.

Hope this helps! -phil.

Hi,

We think this post contains useful information which we would like to share with our public UE4 community. With your approval, we would like to make a copy of this post on the public AnswerHub which includes the discussion but strips out your username and company name. Please let us know if you are okay with this.

Thanks!

Absolutely, and thank you for your support.