unity runtime_error ai_generated true

参数异常:地形碰撞器不支持负的地形高度值

ArgumentException: TerrainCollider does not support negative terrain height values

ID: unity/terrain-collider-mismatch

其他格式: JSON · Markdown 中文 · English
88%修复率
85%置信度
1证据数
2023-03-15首次发现

版本兼容性

版本状态引入弃用备注
2022.3.0f1 active
2023.1.0b10 active
2021.3.20f1 active

根因分析

地形数据高度图包含负值,地形碰撞器无法处理。

English

TerrainData heightmap contains negative values, which TerrainCollider cannot process.

generic

官方文档

https://docs.unity3d.com/Manual/class-TerrainCollider.html

解决方案

  1. In Editor, select Terrain, open Terrain Settings, click 'Flatten' button to set all heights to 0, then re-paint heights with positive values. Alternatively, use script: TerrainData.SetHeights(0, 0, Mathf.Max(0, heights)).
  2. Use a script to clamp negative heights: var heights = terrainData.GetHeights(0, 0, terrainData.heightmapResolution, terrainData.heightmapResolution); for (int y = 0; y < heights.GetLength(0); y++) for (int x = 0; x < heights.GetLength(1); x++) heights[y,x] = Mathf.Max(0.01f, heights[y,x]); terrainData.SetHeights(0, 0, heights);

无效尝试

常见但无效的做法:

  1. Resetting TerrainCollider component in Inspector 70% 失败

    The issue is in TerrainData, not the collider component; resetting doesn't modify heightmap.

  2. Deleting and recreating the terrain 90% 失败

    Loses all terrain data and work; the root cause (negative heights) must be fixed in data.

  3. Setting TerrainCollider.enabled = false then true 80% 失败

    Only toggles collider state, does not address invalid height values.