# 参数异常：缓冲区 'position' 的格式为 'Float3'，但缓冲区 'position' 期望的格式为 'Float4'。

- **ID:** `unity/graphics-buffer-format-mismatch`
- **领域:** unity
- **类别:** runtime_error
- **验证级别:** ai_generated
- **修复率:** 85%

## 根因

计算着色器或图形 API 缓冲区绑定中，缓冲区声明与读取它的着色器/脚本之间的元素大小或格式不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| Unity 2022.3.0f1 | active | — | — |
| Unity 2023.1.0a1 | active | — | — |
| Unity 6000.0.0b1 | active | — | — |

## 解决方案

1. ```
   确保 C# 缓冲区声明与着色器结构体匹配。例如，如果着色器期望 `float4 position`，则使用 stride = sizeof(float) * 4 声明 `ComputeBuffer`，并使用包含 `Vector4 position` 的结构体。然后相应更新 SetBuffer 调用。
   ```
2. ```
   使用 `System.Runtime.InteropServices.Marshal.SizeOf` 根据结构体定义动态计算 stride，以避免手动错误。
   ```

## 无效尝试

- **** — Changing buffer stride without updating shader declarations often leads to data corruption or different errors. (70% 失败率)
- **** — Reimporting assets does not fix runtime buffer format mismatches caused by code changes. (90% 失败率)
