Runtime Instantiation

How to programmatically instantiate built-in or custom Operators at runtime using the Aircada Context API.
Published: 7/10/2026

Programmatic Operator Creation

In advanced configurators, you may need to dynamically spawn Operators at runtime instead of pre-configuring them in the Visual Studio. This is accomplished using the asynchronous create method exposed on this.air.operators.

API Interface & Typings

typescript
create<T = any>(
  type: string,
  properties?: Record<string, any>
): Promise<T | null | undefined>;

Property Initializers & Custom Keys

When invoking create, the second parameter accepts a flat record object (properties) to initialize parameters on the spawned operator:

1. Predefined Properties: Any keys matching fields declared on the Operator class (e.g. @FloatProperty fields) will be set as their initial values.

2. Dynamic Custom Properties: If you specify keys that do not exist on the target Operator type, the framework automatically instantiates them as custom properties on the newly created operator object at runtime.

Code Example

typescript
import { Operator, Context, AircadaContext, Setup, OrbitOperator } from "@aircada/spec";

@Operator({
    name: "Runtime Spawner",
    type: "RUNTIME_SPAWNER"
})
export class RuntimeSpawner {
    @Context()
    air!: AircadaContext;

    @Setup()
    async setup() {
        // Programmatically spawn a built-in Orbit camera operator
        const orbitOperator = await this.air.operators.create<OrbitOperator>("ORBIT", {
            autoRotate: true,
            rotateSpeed: 1.5,
            customPropertyTag: "spawner-allocated" // Creates a custom runtime property
        });

        if (orbitOperator) {
            console.log("Successfully spawned operator at runtime:", orbitOperator.id);
        } else {
            console.warn("Failed to instantiate operator.");
        }
    }
}