0
Answered

Bolt with ARkit and Vuforia in Unity 2017.2

Ryan Miller 3 years ago updated by Lazlo Bonin (Lead Developer) 3 years ago 6

I'm just getting into Unity and have very little programming experience (a high school class in C 20 years ago...)  With Unity assets alone I've been able to create some explorable worlds on an HTC Vive, but now I'm more interested in AR / MR.  Does anyone know how well Bolt works with ARkit and Vuforia?  Is there anything I should watch out for?  Thanks!

Bolt Version:
Unity Version:
Platform(s):
Scripting Backend:
.NET Version (API Compatibility Level):
+1

Never used them, but so far there are no issues with most plugins. Only things I've noticed are, you can't use overrides, lambdas, or plugin events directly in bolt. If any of these are an issue, you can wrap these all in short scripts. There are examples of each of those floating around in the forum. Just do a search if that's an issue.

If you have a question about how to further use those after you've looked I'll definitely give you a hand. It's really simple.

It's a matter of wrapping it in a C# function, and having the parameters or return connected to that function inside. Bolt will auto convert to a node, and all parameters and returns are available to use.

Maybe I'll make my first ever tutorial on how, seen a few people get stuck on these issues.

I'm really having trouble getting Vuforia and Bolt to work together.  I can make things that work in Unity, but they don't work when I build to the iPad.    Vuforia is now a part of Unity 2017.2.0f3, which I figured would make it easier.

The first thing I noticed is the Setup Wizard fails to generate documentation when I have Vuforia in a project.  Not sure if this matters.  

When I go to Generate Inspectors, Vuforia doesn't show up in the list by default, but it's available as "Vuforia.UnityExtensions" and "Vuforia.UnityExtensions.Editor".  I've tried without adding either, adding just the first, and adding both.  Doesn't seem to make a difference in the build.

I've also tried with and without doing the "AOT safe mode", and with and without doing the AOT Pre-Build.  No matter what I do, I have things that work perfectly in Unity, but the Bolt elements simply don't work on the iPad build. Other elements work fine.

However, I'm trying another project from scratch right now that doesn't even have any Bolt elements added yet, only the package imported, inspectors generated, and the various AOT settings, and the action that works fine in Unity won't work on the iPad build.

I just can't figure out if it's something I'm not doing right, or if there's something incompatible between Bolt and Vuforia, which I need for all of the projects I'm working on.

The two projects above were made from scratch.   The first time I tried to simply add bolt into a working Vuforia project, everything worked fine in Unity, but none of the bolt elements worked on the iPad.  Then I read about the AOT steps, so I did those.  That just gave me 3 errors in Unity, and I couldn't build the project. here's one of those errors:

Assets/Generated/Ludiq.Core/AotStubs.cs(1411,27): error CS1061: Type DefaultTrackableEventHandler' does not contain a definition forrunInEditMode' and no extension method runInEditMode' of typeDefaultTrackableEventHandler' could be found. Are you missing an assembly reference?

"DefaultTrackableEvenHandler" is a script from Vuforia.   I didn't get these errors and could build until I ran the AOT pre-build, but then again the Bolt features only worked in Unity and not the actual build...Thanks for any help you might be able to provide!

Two of the errors look like the one above, then the other one is this:

NullReferenceException: Object reference not set to an instance of an object
UnityEngine.GUILayout.FlexibleSpace () (at /Users/builduser/buildslave/unity/build/Runtime/IMGUI/Managed/GUILayout.cs:282)
Ludiq.AotPreBuildPage.OnContentGUI () (at C:/Users/Lazlo/Projects/Ludiq/Ludiq.Core/Editor/Windows/AotPreBuildWindow/AotPreBuildPage.cs:64)
Ludiq.Page.DrawContent () (at C:/Users/Lazlo/Projects/Ludiq/Ludiq.Core/Editor/Windows/Page.cs:56)
Ludiq.SinglePageWindow`1[TPage].OnGUI () (at C:/Users/Lazlo/Projects/Ludiq/Ludiq.Core/Editor/Windows/SinglePageWindow.cs:69)
Ludiq.WrappedEditorWindow.OnGUI () (at C:/Users/Lazlo/Projects/Ludiq/Ludiq.Core/Editor/Windows/WrappedEditorWindow.cs:41)
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:222)
Rethrow as TargetInvocationException: Exception has been thrown by the target of an invocation.
System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MonoMethod.cs:232)
System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) (at /Users/builduser/buildslave/mono/build/mcs/class/corlib/System.Reflection/MethodBase.cs:115)
UnityEditor.HostView.Invoke (System.String methodName, System.Object obj) (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:285)
UnityEditor.HostView.Invoke (System.String methodName) (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:278)
UnityEditor.HostView.OldOnGUI () (at /Users/builduser/buildslave/unity/build/Editor/Mono/HostView.cs:107)
UnityEngine.Experimental.UIElements.IMGUIContainer.DoOnGUI (UnityEngine.Event evt) (at /Users/builduser/buildslave/unity/build/Runtime/UIElements/Managed/IMGUIContainer.cs:127)

Update!  I was able to get the project with the 3 errors to work.  I had an old, unused and incomplete macro with nodes from the "DefaultTrackableEventHandler" script sitting in my macro folder.  I'm 99% sure I wasn't using it still on any objects, but when I deleted the macro, and ran the pre-build again, I was able to build the project and use it on the iPad.  A few things seem off, but some of the Bolt stuff is working for sure, I just need to check more in the morning.

I'm still not sure why the ones I started from scratch didn't work, but I'll try again tomorrow on that.

Answered

Hi Ryan,

Glad you got it working! I'll try to shed some light on the process and what might have gone wrong.

Generating Documentation or Inspectors is optional. If either fails, it won't stop Bolt or your build from working (but please submit a bug report with the error nonetheless!). You can find our why documentation generation has failed by clicking the "Show Log..." button next to the failed step.

When building for AOT, I recommend leaving AOT Safe-Mode enabled. Otherwise you might have access to methods or properties that cannot be used in AOT. 

AOT Pre-Build is absolutely essential before building for any AOT platform. Otherwise, you'll get MissingMethodExceptions all over the place once you test your game.

What I think might have happened here is that you had a macro using the Run In Edit Mode property. As mentioned in the documentation, this property is only available in the editor, which is why Bolt couldn't find it when trying to create AOT stubs for it. Since this macro was in your assets file, it was parsed for stubs, even if it wasn't used anywhere. Deleting the macro (or the Run in edit mode node) and re-generating AOT stubs fixed this problem.

That GUILayout error you're getting is just a harmless warning, no worries!

Let me know if you encounter any other issue,

Cheers,

Lazlo

Just a heads up: starting in v.1.2.3, runInEditMode will no longer be included in the Expose unit for MonoBehaviour to avoid this error by default.