Skip to main content
This example runs Edge Impulse inference inside a Unity XR app on Meta Quest 3 or 3S. A virtual conveyor carries bottles past an inspection station, where a FOMO object detection model checks each bottle’s cap. A reject arm pushes the bottles with a bad cap off the belt. Everything runs on the headset, with no network connection. The Quest runs Android, so the example uses the same Edge Impulse C++ library you would deploy to a phone, compiled as a native plugin and called from Unity through P/Invoke. It’s the Android series NDK approach, wrapped for Unity.
Bottles moving along a virtual conveyor past an inspection station, where a reject arm pushes a bottle with a bad cap off the belt

Example repository

Unity project, native plugin sources, and a prebuilt APK.

Public Edge Impulse project

Clone the bottle cap FOMO model into your own account.

What you’ll learn

  • How to run a FOMO model on-device from Unity through a native plugin
  • How to use an Android C++ library deployment in a Meta Quest XR app
  • How to pass pixels from a Unity camera to the model and act on the result in the scene

How it works

A virtual inspection camera in Unity renders the bottle at the inspection point, passes the pixels to the model, and reacts to the result.
1

Deploy the model as a C++ library

In Edge Impulse Studio, go to Deployment, select C++ library, and build. A wrapper in native/ei_fomo.cpp exposes a classify function.
2

Compile a native plugin for each platform

Build the wrapper as libei_fomo.so (Android arm64-v8a, for the Quest) and libei_fomo.dylib (macOS, for the Unity Editor). The repository includes prebuilt copies of both.
3

Run inference from Unity

EdgeImpulseFOMO.cs calls the plugin through P/Invoke. The inspection station classifies each bottle’s cap and treats cap_incorrect as a defect.
4

React in the scene

The reject arm pushes defective bottles off the conveyor, and cap_correct bottles pass through.

Requirements

  • Unity 6000.0.32f1
  • A Meta Quest 3 or 3S in developer mode, or an arm64 Android device
  • URP, XR Interaction Toolkit, OpenXR, and XR Hands (already included in the project)
  • Android NDK r23b, to rebuild the native library with your own model

Quick start

Download the latest APK from the repository’s Releases page and sideload it onto a Quest 3 or 3S, or an arm64 Android device:
To run it in the XR Device Simulator instead, open the project in Unity, open Assets/Scenes/FactoryFloorDemo.unity, and press Play. One FactoryDemo Bootstrap object builds the whole scene in code, including the conveyor, inspection station, reject arm, and HUD, so you can read and adapt it in one place.

Android series

The NDK and C++ SDK deployment path this example builds on.

ExecuTorch

Deploy PyTorch models to Android with ExecuTorch and Edge Impulse.