Unity-Technologies/UnityCsReference · error · ArgumentOutOfRangeException

Unknown vertex format {format}

Error message

Unknown vertex format {format}

What it means

Thrown by ConvertFormatToSize when a VertexAttributeFormat value is not one of the handled cases (Float32, Float16, the 16/8-bit UNorm/SNorm/UInt/SInt variants). Acts as a defensive exhaustive-switch guard for a format expected to map to a byte size.

Source

Thrown at Editor/Mono/Inspector/ModelInspector.cs:322

            switch (format)
            {
                case VertexAttributeFormat.Float32:
                case VertexAttributeFormat.UInt32:
                case VertexAttributeFormat.SInt32:
                    return 4;
                case VertexAttributeFormat.Float16:
                case VertexAttributeFormat.UNorm16:
                case VertexAttributeFormat.SNorm16:
                case VertexAttributeFormat.UInt16:
                case VertexAttributeFormat.SInt16:
                    return 2;
                case VertexAttributeFormat.UNorm8:
                case VertexAttributeFormat.SNorm8:
                case VertexAttributeFormat.UInt8:
                case VertexAttributeFormat.SInt8:
                    return 1;
                default:
                    throw new ArgumentOutOfRangeException(nameof(format), format, $"Unknown vertex format {format}");
            }
        }

        static string GetAttributeString(VertexAttributeDescriptor attr)
        {
            var format = attr.format;
            var dimension = attr.dimension;
            var str = $"{format} x {dimension} ({ConvertFormatToSize(format) * dimension} bytes)";
            if (attr.stream != 0)
                str += $", stream {attr.stream}";
            return str;
        }

        static long CalcTotalIndices(Mesh mesh)
        {
            return mesh.GetTotalIndexCount();
        }

View on GitHub (pinned to 225b0fbdb5)

Solutions

  1. Open the project in the Unity version that matches or exceeds the one that produced the mesh.
  2. Re-import / re-export the model from source so vertex formats align with the editor.
  3. If writing tooling, validate attr.format against the known set before calling ConvertFormatToSize.

Example fix

// before
int size = ConvertFormatToSize(attr.format);

// after
var known = attr.format switch {
    VertexAttributeFormat.Float32 => 4,
    VertexAttributeFormat.Float16 => 2,
    // ...
    _ => -1
};
if (known < 0) { Debug.LogWarning($"Unsupported vertex format {attr.format}"); return; }
Defensive patterns

Strategy: validation

Validate before calling

static readonly HashSet<VertexAttributeFormat> s_KnownFormats = new HashSet<VertexAttributeFormat> {
    VertexAttributeFormat.Float32, VertexAttributeFormat.Float16,
    VertexAttributeFormat.UNorm16, VertexAttributeFormat.SNorm16,
    VertexAttributeFormat.UInt16, VertexAttributeFormat.SInt16,
    VertexAttributeFormat.UNorm8, VertexAttributeFormat.SNorm8,
    VertexAttributeFormat.UInt8, VertexAttributeFormat.SInt8
};
bool IsKnownFormat(VertexAttributeDescriptor a) => s_KnownFormats.Contains(a.format);

Type guard

static bool IsKnownFormat(VertexAttributeFormat f) => Enum.IsDefined(typeof(VertexAttributeFormat), f);

Try / catch

try { ConvertFormatToSize(attr.format); }
catch (ArgumentOutOfRangeException) { Debug.LogWarning($"Unknown format {attr.format}"); }

Prevention

When it happens

Trigger: Mesh inspection path (ModelInspector / mesh import preview) encountering a vertex attribute format introduced in a newer Unity version than the editor handling it, or a corrupt/malformed mesh with an out-of-range format value.

Common situations: Opening a mesh serialized by a newer Unity build that uses a VertexAttributeFormat not present in the running editor's enum. Asset corruption producing an invalid format integer. Editor version mismatch on imported models.

Related errors


AI-assisted analysis of Unity-Technologies/UnityCsReference@225b0fbdb5 (2026-08-13). Data as JSON: /api/errors/7082f3846c517233. Report an issue: GitHub.