stride3d/stride · error · ArgumentNullException

path

Error message

path

What it means

NavigationComponent.TryFindPath fills the caller-supplied list with waypoints for the found path. It throws ArgumentNullException when the path list is null; a null list cannot be distinguished from 'no path found', so the library treats it as a programming error rather than returning false.

Solutions

  1. Instantiate the list before calling: new List<Vector3>() passed as the path argument
  2. Reuse a pre-allocated member list across path queries to avoid per-frame allocations
  3. Note the method returns false (no throw) when the navigation mesh is null — only a null list throws; keep the list non-null and check the return value

Example fix

// before
IList<Vector3> path = null;
navigationComponent.TryFindPath(start, end, path, querySettings);
// after
var path = new List<Vector3>();
if (navigationComponent.TryFindPath(start, end, path, querySettings))
{
    // use path
}
Defensive patterns

Strategy: validation

Validate before calling

var path = new List<Vector3>();
if (path == null) throw new InvalidOperationException("path list must be initialized");

Type guard

static bool HasPathList(IList<Vector3> path) => path != null;

Try / catch

try
{
    found = navigationComponent.TryFindPath(start, end, path, querySettings);
}
catch (ArgumentNullException)
{
    found = false; // log: path list was null
}

Prevention

When it happens

Trigger: Calling TryFindPath(start, end, null, querySettings) — e.g. declaring the output list but forgetting to instantiate it, or forwarding an uninitialized field.

Common situations: AI agent code requesting paths before initializing the waypoint list; passing a property that is still null on first frame; misreading the API as allocating the result list itself.

Related errors


AI-assisted analysis of stride3d/stride@96fad776d2 (2026-09-14). Data as JSON: /api/errors/70f094aab46e0bbc. Report an issue: GitHub.

Appendix: source

Thrown at sources/engine/Stride.Navigation/NavigationComponent.cs:113

        /// <param name="path">The resulting collection of waypoints for the found path, if any (at least 2 if a path was found)</param>
        /// <returns>True if a valid path was found</returns>
        public bool TryFindPath(Vector3 start, Vector3 end, IList<Vector3> path)
        {
            return TryFindPath(start, end, path, NavigationQuerySettings.Default);
        }

        /// <summary>
        /// Finds a path from point <paramref cref="start"/> to <paramref cref="end"/>
        /// </summary>
        /// <param name="start">The starting location of the pathfinding query</param>
        /// <param name="end">The ending location of the pathfinding query</param>
        /// <param name="querySettings">Advanced settings to be provided to the navigation mesh query</param>
        /// <param name="path">The resulting collection of waypoints for the found path, if any (at least 2 if a path was found)</param>
        /// <returns>True if a valid path was found</returns>
        public bool TryFindPath(Vector3 start, Vector3 end, IList<Vector3> path, NavigationQuerySettings querySettings)
        {
            if (path == null)
                throw new ArgumentNullException(nameof(path));
            if (RecastNavigationMesh == null)
                return false;

            start -= SceneOffset;
            end -= SceneOffset;
            if (!RecastNavigationMesh.TryFindPath(start, end, path, querySettings))
                return false;
            
            for (int i = 0; i < path.Count; i++)
            {
                path[i] += SceneOffset;
            }
            return true;
        }

        /// <summary>
        /// Performs a raycast on the navigation mesh to perform line of sight or similar checks. Starts from the entity's current world position
        /// </summary>

View on GitHub (pinned to 96fad776d2)