[Plugin] Leap Motion - Event Driven

Thanks for the reply! I’d actually poked around the plugin code myself and came to a similar conclusion.

One thing to note is that simply making all the functions BlueprintNativeEvents means that any C++ classes that extend ILeapEventInterface must explicitly provide definitions for all the BlueprintNativeEvents in the interface. For me this means seventeen empty stub functions, for the five or so events I actually care about. Could be worse, but still pretty messy to deal with. Trying to put stub definitions inside of the interface doesn’t work, as this results in a compiler error about being unable to instantiate abstract classes. I assume this is unreal trying to enforce interfaces as function declaration only.

I was thinking about other solutions, but I couldn’t think of any that felt strictly ‘better’. There’s splitting up the LeapEventInterface into several smaller interfaces (hand, finger, gesture, passthrough?), but that’d require some significant changes in LeapController, and it could be disruptive for existing projects. On the plus side, it could result in fewer extraneous event calls, depending on how its implemented. Another possibility would be to use the regular C++ virtual function for native implementation, as that can have an overridable implementation in the interface, and then wrap that and the BlueprintImplementable function in a function:

.h


UFUNCTION(BlueprintNativeEvent, Category = "Leap Interface Event")
	void OnLeapHandMoved(ULeapHand* hand);
	virtual void OnLeapHandMoved_Native(ULeapHand* hand);
	void LeapHandMoved_Exec(ULeapHand* hand)

.cpp


void OnLeapHandMoved_Native(ULeapHand* hand) {
	//stub function so implementation is optional};

void LeapHandMoved_Exec(ULeapHand* hand) {
	OnLeapHandMoved_Native(hand);
	ILeapEventInterface::Execute_OnLeapHandMoved(this, hand);//not sure if this would work, havent tested
}

But then that removes the possibility of doing things like defining an event in C++ and then overriding it in a blueprint child.