{"record":{"id":"acbbfadd8ec5a269","repo":"stride3d/stride","slug":"nameof-heightscale-should-be-1-in-heighttype-type","errorCode":null,"errorMessage":"{ nameof(heightScale) } should be 1 in { heightType } type.","messagePattern":"(.+?) should be 1 in (.+?) type\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Engine/HeightmapUtils.cs","lineNumber":31,"sourceCode":"            try\n            {\n                // Size\n\n                if (size.X < HeightfieldColliderShape.MinimumHeightStickWidth || size.Y < HeightfieldColliderShape.MinimumHeightStickLength)\n                {\n                    throw new ArgumentException($\"{ nameof(size) } parameters should be greater than or equal to 2.\");\n                }\n\n                // HeightScale\n\n                if (MathUtil.IsZero(heightScale))\n                {\n                    throw new ArgumentException($\"{ nameof(heightScale) } is 0.\");\n                }\n\n                if ((heightType == HeightfieldTypes.Float) && !MathUtil.IsOne(heightScale))\n                {\n                    throw new ArgumentException($\"{ nameof(heightScale) } should be 1 in { heightType } type.\");\n                }\n\n                // HeightRange\n\n                if (heightRange.Y < heightRange.X)\n                {\n                    throw new ArgumentException($\"{ nameof(heightRange) }.{ nameof(heightRange.Y) } should be greater than { nameof(heightRange.X) }.\");\n                }\n\n                if (Math.Abs((heightRange.Y / heightScale) - (heightRange.X / heightScale)) < 1)\n                {\n                    throw new ArgumentException($\"{ nameof(heightRange) } is too short.\");\n                }\n\n                if ((heightType == HeightfieldTypes.Byte) &&\n                    (Math.Sign(heightRange.X) + Math.Sign(heightRange.Y)) == 0)\n                {\n                    throw new ArgumentException($\"Can't handle { nameof(heightRange) } included both of positive and negative in { heightType } type.\");","sourceCodeStart":13,"sourceCodeEnd":49,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Engine/HeightmapUtils.cs#L13-L49","documentation":"For HeightfieldTypes.Float heightfields, Stride requires HeightScale to be exactly 1, because float height data already stores absolute values and Bullet's float heightfield has no scaling step. CheckHeightParameters throws ArgumentException when type is Float and scale != 1.","triggerScenarios":"Calling CheckHeightParameters (or creating a collider) on a Float-type heightmap whose HeightScale is 0.5, 2, or any value other than 1.","commonSituations":"Changing a heightmap's HeightType from Short/Byte (which use scale) to Float while keeping the old scale; authoring float terrains exported from tools with a baked scale factor.","solutions":["Set HeightScale = 1 for Float heightmaps.","Bake the desired scaling into the float height values themselves.","Switch HeightType to Short/Byte if you need a non-1 scale.","Run IsValid() first and surface a clear message to users."],"exampleFix":"// before\nheightmap.HeightType = HeightfieldTypes.Float;\nheightmap.HeightScale = 2.0f;\n// after\nheightmap.HeightType = HeightfieldTypes.Float;\nheightmap.HeightScale = 1.0f; // scale must be 1 for Float","handlingStrategy":"validation","validationCode":"if (heightType == HeightfieldTypes.Float) heightScale = 1f;","typeGuard":"bool ValidFloatScale(HeightfieldTypes t, float s) => t != HeightfieldTypes.Float || MathUtil.IsOne(s);","tryCatchPattern":"try { CheckHeightParameters(size, type, range, scale, true); } catch (ArgumentException) { /* force scale=1 or change type */ }","preventionTips":["Reset HeightScale to 1 whenever HeightType changes to Float","Bake scaling into float data instead","Test heightmap config changes in CI"],"tags":["csharp","argument-validation","physics","heightfield-types"],"backgroundTag":"invalid-argument-value","analyzedSha":"96fad776d210c221682aac1ccdf4c79dc046fc38","analyzedAt":"2026-09-14T02:59:31.279Z","contentChangedAt":"2026-09-14T02:59:31.279Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}