Basic Inference
The quickest way to confirm ONNX Runtime is working in your project.
What it does
Loads a tiny (185-byte) ONNX model that is embedded directly in the script
(no .onnx file, no download) and runs it. The model computes, element-wise:
output = input * 2 + 1
With input = [1, 2, 3] the expected output is [3, 5, 7].
How to run
Import this sample from the Package Manager (ONNX Runtime → Samples → Basic Inference → Import).
Create an empty GameObject in a scene and add the Basic Inference Sample component (
BasicInferenceSample).Enter Play Mode and check the Console:
[ONNX Runtime] input = [1, 2, 3] [ONNX Runtime] output = [3, 5, 7] (expected [3, 5, 7]) [ONNX Runtime] Basic inference succeeded ✅
Key API
using var session = new InferenceSession(modelBytes);
var inputs = new List<NamedOnnxValue>
{
NamedOnnxValue.CreateFromTensor("input", new DenseTensor<float>(data, new[] { 1, 3 }))
};
using var results = session.Run(inputs);
float[] output = results.First().AsTensor<float>().ToArray();