{"record":{"id":"4d741fae885ba89b","repo":"stride3d/stride","slug":"nameof-heightstickarraysource-is-a-null","errorCode":null,"errorMessage":"{ nameof(HeightStickArraySource) } is a null.","messagePattern":"(.+?) is a null\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"sources/engine/Stride.Physics/Data/HeightfieldColliderShapeDesc.cs","lineNumber":103,"sourceCode":"                return null;\n            }\n\n            var arrayLength = heightStickArraySource.HeightStickSize.X * heightStickArraySource.HeightStickSize.Y;\n\n            var unmanagedArray = new UnmanagedArray<T>(arrayLength);\n\n            heightStickArraySource.CopyTo(unmanagedArray, 0);\n\n            return unmanagedArray;\n        }\n\n        /// <summary>\n        /// Get the centering offset that will be added to the local offset of the collider shape.\n        /// </summary>\n        /// <returns>The value that will be added to the local offset of the collider shape in order to center specific height.</returns>\n        public float GetCenteringOffset()\n        {\n            if (HeightStickArraySource == null) throw new InvalidOperationException($\"{ nameof(HeightStickArraySource) } is a null.\");\n\n            return Centering.Enabled ?\n                GetCenteringOffset(HeightStickArraySource.HeightRange, Centering.CenterHeight) :\n                0f;\n        }\n\n        public ColliderShape CreateShape(IServiceRegistry services)\n        {\n            object unmanagedArray;\n\n            switch (HeightStickArraySource.HeightType)\n            {\n                case HeightfieldTypes.Float:\n                {\n                    unmanagedArray = CreateHeights<float>(HeightStickArraySource);\n                    break;\n                }\n                case HeightfieldTypes.Short:","sourceCodeStart":85,"sourceCodeEnd":121,"githubUrl":"https://github.com/stride3d/stride/blob/96fad776d210c221682aac1ccdf4c79dc046fc38/sources/engine/Stride.Physics/Data/HeightfieldColliderShapeDesc.cs#L85-L121","documentation":"HeightfieldColliderShapeDesc.GetCenteringOffset() computes the vertical offset needed to center a heightfield shape. It throws InvalidOperationException when HeightStickArraySource is null, since the height range needed for the calculation is unavailable.","triggerScenarios":"Calling GetCenteringOffset() (directly or via shape creation) on a HeightfieldColliderShapeDesc whose HeightStickArraySource property was never assigned.","commonSituations":"Creating a heightfield collider from script without populating HeightStickArraySource; a deserialized asset where the heightstick array reference is missing; editor-created shapes where the source data was deleted.","solutions":["Assign a valid HeightStickArraySource (with height data and HeightRange) before building the shape","Validate HeightStickArraySource != null before calling GetCenteringOffset() or creating the shape","If centering is not needed, note it still requires the source because HeightRange comes from it"],"exampleFix":"// before\nvar desc = new HeightfieldColliderShapeDesc();\nfloat offset = desc.GetCenteringOffset(); // throws\n// after\ndesc.HeightStickArraySource = new HeightStickArraySourceDesc { /* height data */ };\nfloat offset = desc.GetCenteringOffset();","handlingStrategy":"validation","validationCode":"if (desc.HeightStickArraySource == null)\n    throw new InvalidOperationException(\"HeightStickArraySource must be set before building a heightfield shape.\");","typeGuard":null,"tryCatchPattern":"try { var offset = desc.GetCenteringOffset(); }\ncatch (InvalidOperationException) { /* assign HeightStickArraySource and retry */ }","preventionTips":["Populate HeightStickArraySource before any shape construction","Validate asset references after deserialization","Check heightfield configs in editor for missing source data"],"tags":["physics","heightfield","csharp"],"backgroundTag":"null-argument","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"}