Skip to content
Calling Infinio from code

Calling Infinio from code

Assembly reference

Infinio.Runtime has autoReferenced: true in its assembly definition, so any plain MonoBehaviour can add using Infinio.Graph; at the top of the file with no asmdef setup required.

Getting the binary

Serialize the compiled binary as a field on your component:

[SerializeField] private InfinioBinary graphAsset;

InfinioBinary is the sub-asset that lives inside an InfinioGraphAsset. In the inspector it appears as a child of the graph asset — drag that child, not the graph asset itself.

Creating an instance

The static factory is the quickest path:

InfinioInstance instance = InfinioInstance.Spawn(graphAsset, transform.position, Quaternion.identity);

Spawn creates a GameObject, assigns the binary, and calls Evaluate immediately. You can also add the component manually and assign the binary yourself:

var go = new GameObject("My Infinio Instance");
var instance = go.AddComponent<InfinioInstance>();
instance.graphAsset = graphAsset;
instance.Evaluate();

Write-then-evaluate contract

Set(stableName, value) is deferred and write-only. It records the value but does not evaluate the graph. Batch all your parameter changes, then call Evaluate or TryEvaluate once.

Before a per-frame Set loop, guard the parameter name up front so a typo does not become a silent no-op:

if (!instance.TryGet("Height", out float _))
    Debug.LogError("Binary exposes no float parameter named 'Height'.");

Evaluate() is shorthand for TryEvaluate(out _). Use TryEvaluate when you need the outcome at the call site:

if (instance.TryEvaluate(out InfinioEvalReport report))
{
    // Check warnings even on success: they signal degraded output.
    if (report.Warnings.Any)
        Debug.Log($"Eval warnings: 0x{report.Warnings.Bits:X}");
}
else
{
    // report.Status holds the failure reason; OutputMesh holds the last successful result.
    Debug.Log($"Eval failed: {report.Status}");
}

Hooks

Three events fire after each evaluation, in this order:

  1. The evaluator records any warnings onto the report.
  2. OnEvaluated fires with the raw staging buffer:
    public event Action<float[]> OnEvaluated;
  3. The mesh is uploaded to the MeshFilter.
  4. MeshUploaded fires with the uploaded mesh:
    public event Action<Mesh> MeshUploaded;

OutputMesh is instance-owned. Never call Destroy on it. If you need a detached copy that survives the next evaluation, use BakeToMesh() instead.

MeshUploaded is not fired when the graph produced no mesh output, when no MeshFilter is attached, or when evaluation aborted and HoldLastGood kicked in.

Spawn points

If the graph contains scatter output, retrieve the placement descriptors after an evaluation:

SpawnDescriptor[] points = instance.GetSpawnPoints();

Note: “spawn points” here means the graph’s scatter placement output. The word “spawn” appears twice on this class with different meanings: InfinioInstance.Spawn is the static factory that creates an instance GameObject; GetSpawnPoints returns the graph’s scatter output. They are unrelated.

Threading

All evaluation happens on the main thread. One evaluation runs at a time. Off-main-thread evaluation is not supported.

Platform support

Windows Mono and IL2CPP player builds have been built and run. No other platform has been built or run against the current codebase.


A full per-node API reference comes later.