Unity-Technologies/ml-agents · error · UnityAgentsException
Expected parentIndices[0] to be -1, got {parentIndices[0]}
Error message
Expected parentIndices[0] to be -1, got {parentIndices[0]} What it means
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.
Source
Thrown at com.unity.ml-agents/Runtime/Sensors/PoseExtractor.cs:185
/// </summary>
/// <param name="index">The index of the pose to check.</param>
/// <returns>True if the pose is enabled; otherwise, false.</returns>
public bool IsPoseEnabled(int index)
{
return m_PoseEnabled[index];
}
/// <summary>
/// Initialize with the mapping of parent indices.
/// The 0th element is assumed to be -1, indicating that it's the root.
/// </summary>
/// <param name="parentIndices">An array mapping each pose to its parent index. The root should be -1.</param>
protected void Setup(int[] parentIndices)
{
#if DEBUG
if (parentIndices[0] != -1)
{
throw new UnityAgentsException($"Expected parentIndices[0] to be -1, got {parentIndices[0]}");
}
#endif
m_ParentIndices = parentIndices;
var numPoses = parentIndices.Length;
m_ModelSpacePoses = new Pose[numPoses];
m_LocalSpacePoses = new Pose[numPoses];
m_ModelSpaceLinearVelocities = new Vector3[numPoses];
m_LocalSpaceLinearVelocities = new Vector3[numPoses];
m_PoseEnabled = new bool[numPoses];
// All poses are enabled by default. Generally we'll want to disable the root though.
for (var i = 0; i < numPoses; i++)
{
m_PoseEnabled[i] = true;
}
}
View on GitHub (pinned to 3ecb446f75)
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.
Example fix
// before
Setup(new[] { 0, 0, 1 }); // parentIndices[0] = 0, not -1
// after
Setup(new[] { -1, 0, 1 }); // root first, then children Defensive patterns
Strategy: validation
Validate before calling
if (parentIndices == null || parentIndices.Length == 0 || parentIndices[0] != -1)
throw new ArgumentException("parentIndices[0] must be -1 (root)"); Type guard
static bool IsValidParentIndices(int[] p) => p != null && p.Length > 0 && p[0] == -1;
Try / catch
try { Setup(parentIndices); } catch (UnityAgentsException e) { Debug.LogError($"Bad parent map: {e.Message}"); } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Index out of bounds, expected a number between 0 and {Length
- Enumerator not started.
- Enumerator has reached the end already.
- Action spaces with both continuous and discrete actions are
- Call to SendInfoToBrain when Agent hasn't been initialized.P
AI-assisted analysis of Unity-Technologies/ml-agents@3ecb446f75 (2026-09-02).
Data as JSON: /api/errors/28b3927d4e70388f.
Report an issue: GitHub.