{"record":{"id":"28b3927d4e70388f","repo":"Unity-Technologies/ml-agents","slug":"expected-parentindices-0-to-be-1-got-parentind","errorCode":null,"errorMessage":"Expected parentIndices[0] to be -1, got {parentIndices[0]}","messagePattern":"Expected parentIndices\\[0\\] to be -1, got (.+?)","errorType":"validation","errorClass":"UnityAgentsException","httpStatus":null,"severity":"error","filePath":"com.unity.ml-agents/Runtime/Sensors/PoseExtractor.cs","lineNumber":185,"sourceCode":"        /// </summary>\n        /// <param name=\"index\">The index of the pose to check.</param>\n        /// <returns>True if the pose is enabled; otherwise, false.</returns>\n        public bool IsPoseEnabled(int index)\n        {\n            return m_PoseEnabled[index];\n        }\n\n        /// <summary>\n        /// Initialize with the mapping of parent indices.\n        /// The 0th element is assumed to be -1, indicating that it's the root.\n        /// </summary>\n        /// <param name=\"parentIndices\">An array mapping each pose to its parent index. The root should be -1.</param>\n        protected void Setup(int[] parentIndices)\n        {\n#if DEBUG\n            if (parentIndices[0] != -1)\n            {\n                throw new UnityAgentsException($\"Expected parentIndices[0] to be -1, got {parentIndices[0]}\");\n            }\n#endif\n            m_ParentIndices = parentIndices;\n            var numPoses = parentIndices.Length;\n            m_ModelSpacePoses = new Pose[numPoses];\n            m_LocalSpacePoses = new Pose[numPoses];\n\n            m_ModelSpaceLinearVelocities = new Vector3[numPoses];\n            m_LocalSpaceLinearVelocities = new Vector3[numPoses];\n\n            m_PoseEnabled = new bool[numPoses];\n            // All poses are enabled by default. Generally we'll want to disable the root though.\n            for (var i = 0; i < numPoses; i++)\n            {\n                m_PoseEnabled[i] = true;\n            }\n        }\n","sourceCodeStart":167,"sourceCodeEnd":203,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/com.unity.ml-agents/Runtime/Sensors/PoseExtractor.cs#L167-L203","documentation":"PoseExtractor.Setup validates (in DEBUG builds only) that parentIndices[0] == -1, i.e. the first entry must be the root of the pose hierarchy with no parent. If it isn't, UnityAgentsException is thrown. This guards the invariant that the hierarchy has exactly one well-defined root at index 0.","triggerScenarios":"Calling Setup(int[] parentIndices) where the first element is not -1 — e.g. passing an all-positive array, an array whose root is at another index, or a misbuilt parent map from a custom rig.","commonSituations":"Building a custom PoseExtractor for a custom character rig and forgetting to place the root at index 0; generating parent indices programmatically from a bone hierarchy and starting from a non-root bone; copying an array in the wrong order.","solutions":["Set parentIndices[0] to -1 so the first pose is the root of the hierarchy.","Rebuild the parent map by walking the bone hierarchy from the root outward so the root lands first.","Note this check only fires in DEBUG builds — validate the array yourself in release builds before calling Setup."],"exampleFix":"// before\nSetup(new[] { 0, 0, 1 }); // parentIndices[0] = 0, not -1\n// after\nSetup(new[] { -1, 0, 1 }); // root first, then children","handlingStrategy":"validation","validationCode":"if (parentIndices == null || parentIndices.Length == 0 || parentIndices[0] != -1)\n    throw new ArgumentException(\"parentIndices[0] must be -1 (root)\");","typeGuard":"static bool IsValidParentIndices(int[] p) => p != null && p.Length > 0 && p[0] == -1;","tryCatchPattern":"try { Setup(parentIndices); } catch (UnityAgentsException e) { Debug.LogError($\"Bad parent map: {e.Message}\"); }","preventionTips":["Put the hierarchy root at index 0 with parent -1","Generate parent arrays by walking bones root-first","Remember the check only runs in DEBUG builds — validate in release too"],"tags":["unity","ml-agents","validation","hierarchy","debug-assert"],"backgroundTag":"invalid-input-contract","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}