Getting the Leap to work with Unity (Free Version not Pro)

 

I am lucky enough to have been accepted into the Leap Developer Program. If you do no know what the Leap is, then check out www.leapmotion.com

I have some ideas as to how to use this interface (definitely not as replacement to a touch screen, but something that can use the 3rd dimension since it has “depth”)  Anyway, in order to experiment,  I decided to experiment using a gaming engine and settled on unity3d (www.unity3d.com) as it seems to be quite well supported.

Here started my dilemma  Unity3D has 2 versions, a free one (for companies making less than 100K a year and with some limitations) and a Pro one (quite reasonable price, 1.5K). But, to just experiment, I wanted to use the Free one and not have to shell out 1.5K.

The problem is that in the Free version of Unity, you are not allowed to use a native DLL (you can however use .net managed DLLs).

So, with Leap supporting C# and .net, I thought it would be quite simple to get the free version working… and indeed it was… But, noone seems to have blogged the exact steps, and all posts I have seen, just hint that this is possible without the actual step by steps to how to do it.

Hence… (Drum Roll please)… below are the step by step introductions on how I got it working (really simple after all).

1st, I am running Windows 7, 64Bit and version 0.74 of the SDK (downloaded this morning)

Step 1 – Make sure you have a Leap, and have downloaded the SDK and your leap is working – Run the Leap Visualizer to make sure that the leap is working well.

Step 2 – Locate the Unity Assets folder.  This is located under [SDK Path]\LeapSDK\lib\UnityAssets\Plugins (there are 3 files there – Leap.dll, LeapCShare.dll and LeapCSharp.NET3.5.dll

Step 3 – Locate and make a copy of the Unity Sandbox folder.  [SDK Path]\LeapSDK\Examples\UnitySandbox

Step 4 – Copy the Unity Sandbox folder somewhere else, where we will experiment. I called mine UnityFreeSandbox

Step 5 – Run the UnitySandbox.exe already built under the UnitySandbox folder.  It should run and you show be able to use your leap to interact with the Cube (note the picture below showing that it can detect by finger).

workingUnitySandbox

Step 6 – Now, open the UnitySandbox project within Unity itself. (in UniySandbox folder, Go to subfolder Assets\Scenes folder and open UnitySandbox scene).

Step 7 – Now inside Unity Editor, run the program.  You will note that it will work, but you will get errors logged in the console “License error – plugins are only supported in Unity Pro” (see screen shot below)

WorkingwithinUnitybutwitherrors

Step 8 – Now, within the Unity Editor… Go to Assets\Plugins and you should see 3 files (Leap.dll, LeapCShare.dll and LeapCSharp.NET3.5.dll).  DELETE the 1st 2, so you are only left with LeapCSharp.NET3.5.dll there).

Step 9 – Run the program within Unity and you will note that it will NOT work and the console shows an error (see below)
DllNotFoundException: LeapCSharp
Leap.LeapPINVOKE+SWIGExceptionHelper..cctor ()

NotWorkingwithinUnityFree

Step 10 – Now copy 2 of the 3 files from UnityAssets folder (see step 2) [SDK Path]\LeapSDK\lib\UnityAssets\Plugins , namely, Leap.dll and LeapCShare.dll to the root folder where you copied UnitySandbox – See Step 4 (I called mine UnityFreeSandbox)

Step 11 – Run your project and you should see that it runs, and works with no errors in the console.

Step 12 – Build your project and create an EXE, if you place it in the root folder UnityFreeSandbox where your dlls are, it will work with no problems.  If you want to deploy it, you will need to ensure that the 2 Dlls copied in Step 10 are deployed with your EXE (in the same folder would be my choice)

Step 13 – Enjoy and let me know how you get on with Leap and Unity.

34 thoughts on “Getting the Leap to work with Unity (Free Version not Pro)

  1. Just by chance, do you think the same type of file management will work with the 3D Free version of Blender 2.66? There is not any directions on how to do it for Blender. I really need to know. I am trying myself for many weeks!

    Thanks for any help/suggestions to try!

    Paul ( upretirementman )

    • Not sure about Blender Paul, I have not used it. If it supports managed dlls, then the approach should work as the only interface to leap is through the managed dll… The managed dll itself calls the unmanaged ones, hence they have to be somewhere in the path so it can find them.

    • Hi Besjan,
      sorry, I am not a Unity expert. Just started using it as a cool way to play with the Leap.
      However, I think you would need to use the websocket API? if you want it to work on a web player, as it would need to somehow communicate with the leap device.
      Interesting topic… If I have time once I finish my current experiments, will see if I can have a go at that.

  2. Pingback: Leap Enabling the Unity3D Car Tutorial | Pierre's Blog

  3. Pingback: Leap Enabling the Unity 3D Bootcamp Demo – Step by Step + Leap HUD | Pierre's Blog

  4. Pingback: Menu GUI options for Leap Motion and Unity3D | Pierre's Blog

    • Hi Oliver, I decided to investigate getting this working as I wanted to “play around”. You will have to read and interpret the EULA for your own circumstances. I hope you understand, I cannot comment on that.

  5. A pal tipped me off to try this with the Oculus Rift SDK, which is similarly Pro-only, and it works if one copies OculusPlugin.dll, OculusPlugin_debug.dll, and the folder x86_64 (containing a different OculusPlugin.dll) to the same directory as the built project executable.

    Probably not permitted to actually work on a project doing this, but it’s certainly interesting.

    • Glad to hear it works. At the end of the day all the managed .net code has to call a native dll (even if it ends up as user32.dll at the most basic level) so differentiating between Pro and standard by restricting the call to native versus managed dll seems a bit silly (to me anyway)

  6. Hi,
    i have tried following your turorial, but i am already stuck at step5. LeapVisualizer is working fine, but there is no Leap Input available in the prebuild UnitySandbox.exe. Even tried to open the project in Unity Pro and get a “DllNotFoundException” for LeapCSharp.dll. Tips are greatly appreciated.

    • Hi Maria,
      I assume you are running the UnitySandBox with the Visualizer closed? or at least making sure it has the focus. Since at Step 5, you really have not made any modifications, you are just trying to run the bog-standard example from LeapMotion, you may want to raise this on the Leap Website as an issue. The Leap team is very responsive.

      • Hi,
        reinstalling Unity solved the problem. Now i have to understand how to use the Leap with Unity. Greetings

        • I am glad it is working. Let us know how you get on with the experiments. note that my completed leap enabling the bootcamp demo from unity is available for download from github. you may find following that tutorial useful.

  7. Hey.. Nice share, I have been playing with Leap cont. using Java since I got it last summer. I will surely give this a try as I have been trying to move on to Unity for serious stuff.
    And awesome work on Rock Paper Scissors (y)

  8. Pingback: Tutorial: Empezando a crear aplicaciones con Leap Motion SDK y Unity3D (versión gratuita) | Leap Spain

  9. Many thanks for the tutorial Pierre, but when I run the program in Unity Editor, no input seems to be available from the Leap. Furthermore, even after all the steps, I still get that pesky console error.

    I am using Unity 4.1.5 with the most recent Leap SDK on Windows 8. Should I try reinstalling Unity or do you see another problem here?

    Thanks!

  10. Hi Pierre,

    I’m using Unity Pro and I’d like to use the Leap Motion with Unity Webplayer mode.

    You talk about this in your previous comments.

    Do you have somme good results with Leap Motion and Unity WebPlayer ?

    Let me know. Many thanks.

  11. Pingback: Tutorial: Empezando a crear aplicaciones con Leap Motion SDK y Unity3D (versión gratuita) | Pablo Marcos

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>