{"record":{"id":"9572b31cf74c2b3e","repo":"Unity-Technologies/ml-agents","slug":"no-parent-indices-set","errorCode":null,"errorMessage":"No parent indices set","messagePattern":"No parent indices set","errorType":"exception","errorClass":"NullReferenceException","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Runtime/Sensors/PoseExtractor.cs","lineNumber":149,"sourceCode":"\n        /// <summary>\n        /// Number of total poses in the hierarchy (read-only).\n        /// </summary>\n        public int NumPoses\n        {\n            get { return m_ModelSpacePoses?.Length ?? 0; }\n        }\n\n        /// <summary>\n        /// Get the parent index of the body at the specified index.\n        /// </summary>\n        /// <param name=\"index\">The index of the body whose parent index is to be retrieved.</param>\n        /// <returns>The parent index of the body at the specified index.</returns>\n        public int GetParentIndex(int index)\n        {\n            if (m_ParentIndices == null)\n            {\n                throw new NullReferenceException(\"No parent indices set\");\n            }\n\n            return m_ParentIndices[index];\n        }\n\n        /// <summary>\n        /// Set whether the pose at the given index is enabled or disabled for observations.\n        /// </summary>\n        /// <param name=\"index\">The index of the pose to enable or disable.</param>\n        /// <param name=\"val\">Whether the pose is enabled (true) or disabled (false).</param>\n        public void SetPoseEnabled(int index, bool val)\n        {\n            m_PoseEnabled[index] = val;\n        }\n\n        /// <summary>\n        /// Returns whether the pose at the given index is enabled for observations.\n        /// </summary>","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Runtime/Sensors/PoseExtractor.cs#L131-L167","documentation":"PoseExtractor.GetParentIndex returns the parent index of a body part but throws NullReferenceException when the internal m_ParentIndices array was never initialized. This means Setup() was never called (or was called with null) before querying the pose hierarchy. The library throws this to surface an ordering/lifecycle bug rather than silently returning a wrong parent index.","triggerScenarios":"Calling GetParentIndex (directly or via the parent property) on a PoseExtractor subclass whose Setup(parentIndices) was never invoked, or whose constructor/sensor failed to call Setup before the first observation step.","commonSituations":"Writing a custom Sensor/PoseProvider subclass and forgetting to call Setup with the parent-index array in the constructor or initialization; calling GetParentIndex before the first sensor reset; a subclass overriding Setup incorrectly so the base method never runs.","solutions":["Ensure Setup(parentIndices) is called (with a valid array whose first element is -1) in your PoseExtractor subclass constructor or initialization path before any observation is taken.","Check the call order: any code using GetParentIndex/parent must run after Setup, e.g. after the sensor is added to the Agent.","Debug why Setup was skipped — e.g. an overridden Setup that doesn't call base.Setup, or a conditional initialization branch that never executed."],"exampleFix":"// before\npublic MyPoseExtractor() { }\npublic int Parent(int i) => GetParentIndex(i); // throws: m_ParentIndices null\n// after\npublic MyPoseExtractor()\n{\n    Setup(new[] { -1, 0, 0 }); // root first, then parents\n}\npublic int Parent(int i) => GetParentIndex(i);","handlingStrategy":"validation","validationCode":"if (extractor == null || extractor.GetParentIndexOrNull == null) { /* Setup() not called yet */ }\n// wrap: expose parent indices via a property and check before use\nbool ready = extractor.NumPoses > 0; // only true after Setup","typeGuard":"static bool IsPoseExtractorReady(PoseExtractor e) => e != null && e.NumPoses > 0;","tryCatchPattern":null,"preventionTips":["Always call Setup(parentIndices) in the PoseExtractor subclass constructor","Never query GetParentIndex before the first observation/reset","Don't override Setup without calling base.Setup"],"tags":["unity","ml-agents","null-reference","sensor","initialization-order"],"backgroundTag":"uninitialized-state-access","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}