Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Implement Leap Motion Controller for gesture handling

Hey guys,

I'm struggling with Leap Motions C++ API to get gesture handling in my UE4 project to work. By now, the gesture handling works but the approach seems incredibly hacky to me and i'm pretty sure thats not the best way.

I've got this so far inside a tick function:

     Controller controller;
     if (controller.isConnected()) {
             Frame currentFrame = controller.frame();
             GestureList gestures = currentFrame.gestures();
             SwipeGesture swipe = Gesture::invalid();
             CircleGesture circle = Gesture::invalid();
             for (Gesture g : gestures)
                 switch (g.type())
                 case Gesture::TYPE_CIRCLE:
                     debug(FString::Printf(TEXT("CIRCLE WOOHOOO %d"), currentFrame.id()), FColor::Green);
                     if (g.isValid()) {
                         circle = CircleGesture(g);
                         //custom function
                 case Gesture::TYPE_SWIPE:
                     debug(FString::Printf(TEXT("SWIPE YAAAR %d"), currentFrame.id()), FColor::Blue);
                     if (g.isValid()){
                         swipe = SwipeGesture(g);
                         this->LeapSwipeEvent(swipe, getSwipeDirection(swipe));
                         //custom function

Because I derived from the LeapMotionControllerComponent, i have no "BeginPlay" or similar functions where I could set my controller and its settings once at start, instead i have to set it inside of my tick function over and over again.

Setting up Controller as a variable in header file is not possible aswell, due to its ... strange "instant" constructor trying to directly declare it (-> crash)

Is there any way to do this in a smarter way? And is it somehow possible to set up a Controller object globally, to use it in different functions and somehow set settings at startup? (without a beginplay method)

Any help or examples of actual real code (not leapmotion doc snippets) are appreciated.

Product Version: Not Selected
more ▼

asked Apr 21 '15 at 09:08 AM in C++ Programming

avatar image

16 2 5 6

avatar image zhudongwork Jan 08 '18 at 04:12 AM

Hi,I want to use the Leap Motions C++ API in my UE4 C++ project.But I don't know how to include it.Could you help me?

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

I would create a pointer to a Controller and initialise it in your constructor, you can do this in the plugin class if you're implementing one or else have a singleton class. I did this in my Leap blueprint plugin before the official implementation was available and it worked without issues.

 //in class declaration as private member variable
 Leap::Controller* Controller;

 //In class constructor
 //LeapListener was a custom class inheriting from Leap::Listener    
 Listener = new LeapListener(); 
 Controller = new Leap::Controller(*Listener);

You could use OnRegister() instead of the class constructor. Just make sure you call Super::OnRegister() in your overriden body as well.

more ▼

answered Apr 21 '15 at 09:23 AM

avatar image

1.5k 55 35 73

avatar image LeFxPete Apr 22 '15 at 08:38 AM

Thanks for your suggestions twiddle, i'll try to use the OnRegister function and report back!

Concerning the initialization in my constructor.. ye, that's what I initially wanted to do, but like i already mentioned, this does not work for me :( Just double checked.. It compiles successfully but then throws this crash if I try to start the level in editor Unknown exception - code c06d007e (first/second chance not available)

 KERNELBASE + 109229 bytes
 UE4Editor_MyProjectname!__delayLoadHelper2() + 393 bytes [f:\dd\vctools\delayimp\delayhlp.cpp:315]
 UE4Editor_MyProjectname!_tailMerge_Leap_dll() + 63 bytes

If I debug my level, VS' additional info gives "0xC06D007E: Module not found"..

Have you encountered something similar? I think this one gets thrown because this "early" declaration of Leap stuff cant't find/communicate with the plugin at this level..

If I could fix this issue, this would solve all my problems!

avatar image twiddle Apr 22 '15 at 08:43 AM

Looks like the plugin module isn't loaded at the time you're wanting to access the functionality, or, the plugin module isn't being found on the path for the process.. Did you say if you initialise it in your Tick that this works? If so, that would seem to preclude the latter from being the cause, and maybe it's simply a matter of the plugin module not being loaded into the process at the time the constructor is called. Unfortunately I was making a plugin that consumed the native C++ leap dll rather than using any sort of official integration, so perhaps somebody that's used the integration can offer further comment here..

avatar image LeFxPete Apr 22 '15 at 09:44 AM

I think that's the reason.. it seems it's getting loaded later on and the constructor of my class tries to access it too early.

Yes, If i initialize it in my tick function (which obviously is getting called in editor itself for the first time) it works like a charm..

I also tried to change the loading behaviour somehow in uplugin/uproject files, but that did not change anything and i'm not sure if i put the right LoadingPhases. (I have no experience in modifying these kind of files)

avatar image twiddle Apr 22 '15 at 09:45 AM

At a guess, I'd say the loadingPhase is what you want to be investigating, my advice would be to take a peek at the documentation and see if that has the info, otherwise, maybe try looking at the LoadingPhase that the leap integration module uses?

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question