BabylonJS/Babylon.js · error · Error

Connect failed

Error message

Connect failed

What it means

AbstractSoundSource.outBus setter throws "Connect failed" when the internal _connect(outBus) call returns false after subscribing to the bus's dispose observable. In Babylon.js Audio V2, a sound source must be attached to an output bus (e.g. the default main bus); _connect fails when the underlying audio engine cannot establish the node connection, typically because the engine is not ready/started or the connection target is invalid or already disposed.

Source

Thrown at packages/dev/core/src/AudioV2/abstractAudio/abstractSoundSource.ts:106

        if (this._outBus) {
            if (this._onOutBusDisposed) {
                this._outBus.onDisposeObservable.removeCallback(this._onOutBusDisposed);
                this._onOutBusDisposed = null;
            }
            if (!this._disconnect(this._outBus)) {
                throw new Error("Disconnect failed");
            }
        }

        this._outBus = outBus;

        if (this._outBus) {
            this._onOutBusDisposed = () => {
                this._outBus = null;
            };
            this._outBus.onDisposeObservable.add(this._onOutBusDisposed);
            if (!this._connect(this._outBus)) {
                throw new Error("Connect failed");
            }
        }
    }

    /**
     * The spatial audio features.
     */
    public get spatial(): AbstractSpatialAudio {
        if (this._spatial) {
            return this._spatial;
        }
        return this._initSpatialProperty();
    }

    /**
     * The stereo features of the sound.
     */
    public abstract stereo: AbstractStereoAudio;

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Ensure the AudioEngine is initialized and started before setting outBus: await engineInitAsync (or AudioEngineV2 default engine init) before assignment.
  2. Verify the target bus is not disposed: check it is still in engine.buses / you hold a live reference (e.g. CreateDefaultMainBus or a Bus you created).
  3. Wrap the assignment in try/catch and retry the assignment once the engine is ready.
  4. Update Babylon.js packages; earlier Audio V2 builds had connect timing bugs.

Example fix

// before
const sound = await createSoundAsync("boom.mp3");
sound.outBus = bus; // throws if engine not ready

// after
await AudioEngineV2.Listener.engine.initAsync(); // or await engine started
const bus = engine.buses.find((b) => b.name === "SFX") ?? new AudioBus("SFX");
sound.outBus = bus;
Defensive patterns

Strategy: validation

Validate before calling

function canAssignOutBus(engine, bus) {
  return !!engine && engine.state === 'started' /* or awaited initAsync */ && !!bus && !bus.isDisposed && engine.buses.includes(bus);
}
if (canAssignOutBus(engine, bus)) sound.outBus = bus;

Type guard

function isLiveBus(x) {
  return x instanceof AudioBus && !x.isDisposed;
}

Try / catch

try {
  sound.outBus = bus;
} catch (e) {
  if (e.message === 'Connect failed') {
    await engine.initAsync(); // or retry after engine ready
    sound.outBus = bus;
  } else throw e;
}

Prevention

When it happens

Trigger: Assigning sound.outBus = someBus before AudioEngine is ready (engine not created/started), assigning a bus that has been disposed, or assigning a bus whose underlying node graph cannot accept a connection (e.g. destination bus in a broken state).

Common situations: Setting outBus immediately after creating the engine without awaiting engineInitAsync()/await engine start; capturing a bus that was disposed (its onDisposeObservable fires and clears references but stale handles are reused); migrating from AudioEngineV1 patterns where no readiness await was needed.

Related errors


AI-assisted analysis of BabylonJS/Babylon.js@0592b347b8 (2026-08-30). Data as JSON: /api/errors/37de8e423329b757. Report an issue: GitHub.