BabylonJS/Babylon.js · error · Error

${context}/componentType: Invalid value ${accessor.component

Error message

${context}/componentType: Invalid value ${accessor.componentType}

What it means

Index accessors must use an unsigned integer component type: UNSIGNED_BYTE (5121), UNSIGNED_SHORT (5123), or UNSIGNED_INT (5125). Signed, float, or double component types are rejected with this error because index buffers cannot contain negative or fractional values.

Source

Thrown at packages/dev/loaders/src/glTF/2.0/glTFLoader.pure.ts:2195

     */
    public _loadFloatAccessorAsync(context: string, accessor: IAccessor): Promise<Float32Array> {
        return this._loadAccessorAsync(context, accessor, Float32Array) as Promise<Float32Array>;
    }

    /**
     * @internal
     */
    public _loadIndicesAccessorAsync(context: string, accessor: IAccessor): Promise<IndicesArray> {
        if (accessor.type !== AccessorType.SCALAR) {
            throw new Error(`${context}/type: Invalid value ${accessor.type}`);
        }

        if (
            accessor.componentType !== AccessorComponentType.UNSIGNED_BYTE &&
            accessor.componentType !== AccessorComponentType.UNSIGNED_SHORT &&
            accessor.componentType !== AccessorComponentType.UNSIGNED_INT
        ) {
            throw new Error(`${context}/componentType: Invalid value ${accessor.componentType}`);
        }

        if (accessor._data) {
            return accessor._data as Promise<IndicesArray>;
        }

        if (accessor.sparse) {
            const constructor = GLTFLoader._GetTypedArrayConstructor(`${context}/componentType`, accessor.componentType);
            accessor._data = this._loadAccessorAsync(context, accessor, constructor);
        } else {
            const bufferView = ArrayItem.Get(`${context}/bufferView`, this._gltf.bufferViews, accessor.bufferView);
            accessor._data = this.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView).then((data) => {
                return GLTFLoader._GetTypedArray(context, accessor.componentType, data, accessor.byteOffset, accessor.count);
            });
        }

        return accessor._data as Promise<IndicesArray>;
    }

View on GitHub (pinned to 0592b347b8)

Solutions

  1. Set the indices accessor componentType to 5121, 5123, or 5125 and convert the data accordingly.
  2. Point primitive.indices at a properly typed unsigned-int accessor.
  3. Re-export the mesh with a compliant exporter.
  4. Validate with glTF-Validator to catch componentType mismatches.

Example fix

// before
"accessors": [{ "type": "SCALAR", "componentType": 5126, "count": 36 }]
// after
"accessors": [{ "type": "SCALAR", "componentType": 5125, "count": 36 }]
Defensive patterns

Strategy: type-guard

Validate before calling

const IDX_COMPONENTS = [5121, 5123, 5125];
for (const prim of gltf.meshes?.flatMap(m => m.primitives) ?? []) {
  const acc = gltf.accessors?.[prim.indices!];
  if (acc && !IDX_COMPONENTS.includes(acc.componentType)) {
    throw new Error(`Indices componentType must be unsigned int, got ${acc.componentType}`);
  }
}

Type guard

function isUnsignedIndexComponent(c: number): c is 5121 | 5123 | 5125 {
  return c === 5121 || c === 5123 || c === 5125;
}

Try / catch

try { await loadAsset(); } catch (e) {
  if (/componentType: Invalid value/.test((e as Error).message)) {
    // convert index data to UNSIGNED_INT (5125) and retry
  }
}

Prevention

When it happens

Trigger: A primitive's indices accessor uses componentType such as FLOAT (5126) or a signed int, whether from a buggy exporter, hand-editing, or a converter that reused a vertex-data accessor for indices.

Common situations: Converters mapping index data as float arrays, hand-built glTF where componentType constants are misremembered (e.g. 5126 instead of 5125), assets optimized incorrectly.

Understand the failure class

Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.

Related errors


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