Learning Analytics in Augmented Reality (or LAAR for short), the EU funded project I’ve been working on as part of my position in PAL, looks at how technology can support learning. In particular it looks at work-based training where augmented environments will soon be training new employees, teaching them and evaluating their performance. In order to perform the learning analytics we must gather data on the users while using the prototype applications. The Experience API (or xAPI) was chosen to do this.
TinCan is an implementation of the xAPI standard, provided by Rustici Software. It has been ported into a number of languages but for Hololens / Unity development we are only worried about the C# version which can be found here.
Now I had a few problems making this work in Unity… When you drop TinCan into your project, it’s not going to compile. There are a few dependencies that do not work. Something to do with system.net not include in mono or C# or UWP… I’ve spent more time than I’d like to admit on this. Let’s ignore that and instead look at the solutions, here is how you can fix all those redlines:
Fix 1: Use Unity.WebRequest
This works and has been tested on Unity 2017.2.1f1 (and should work for all newer versions too). I’ve used this to build Hololens applications and have also seen it deployed on an IOS compile of a unity project.
This solution replaces the “System.Net” calls with Unitys native “Unity.WebRequest”. It’s embarrassingly simple.
Configuration:
- Scripting Runtime Version: Experimental (.NET 4.6 Equivalent)
- Api Compatibility Level: .NET 4.6
Steps:
- Replace all references to HttpWebRequest with Unity.WebRequest (Download it here)
Fix 2: Use IL2CPP
This works and has been tested on Unity 2018.2.2f1.
Another solution that works for the latest Unity release was to
- Go to File > Building Settings… > Player Settings… > Other settings > Configuration > Scripting Backend
- Set the “Scripting Backend” to “IL2CPP”
- Replace the reference “System.Web.WebUtility” with “System.Net.WebUitility”
The code will still not compile however, throwing up a number of errors. It appears when you hit compile the project has the same dependency errors that occurred in 2017, to do with only get a subset of .net or something…
The solution I found that seemed to work for Unity 2018.2.2f1 involved making a few basic changes to the Remotelrs class and setting the Scripting Backend to IL2CPP. (The mixed reality toolkit sets this to .Net by default but Unity now warns .Net is going to be deprecated… so we will see how this plays out.) Mentioned here but also mentions UWP is fully supported in IL2CPP. This version of Unity a warning pops-up if you have .NET set as the scripting backend which suggest that setting is being deprecated… so we will all probably be compiling into IL2CPP in the future no-matter what
End
Thank you for reading, I hope this post has been helpful. Any thoughts, questions, comments, criticisms? I’ll happily answer all.
Thank you very much for this post. It is working fine in editor, however I cannot get xAPI to work in an android build using IL2CPP. It works fine in Mono. Any advises?
What’s the error message?