Seams bug in NavMeshQuery API with custom agentType

When I try NavMeshQuery.BeginFindPath with custom agentType, I got error:
ArgumentException: The start location doesn't belong to any active NavMesh surface.

I created NavMeshLocation with query oreration, but it didn't work anyway with custom agentType, with default agentType (Humanoid) all works fine.

using UnityEngine;
using UnityEngine.Experimental.AI;
using UnityEngine.AI;
using Unity.Collections;

public class Behavior : MonoBehaviour {

    NavMeshWorld world;
    int agentID;
    void Start () {

        agentID = GameObject.Find("Cube").GetComponent<NavMeshAgent>().agentTypeID;

        world = NavMeshWorld.GetDefaultWorld();
        NavMeshQuery query = new NavMeshQuery(world, Unity.Collections.Allocator.Temp, 100);

        NavMeshLocation location = query.MapLocation(new Vector3(0, 0, 0), new Vector3(10, 10, 10), agentID);
        NavMeshLocation end = query.MapLocation(new Vector3(5, 0, 5), new Vector3(10, 10, 10), agentID);
        PathQueryStatus status = query.BeginFindPath(location, end);
        int s;
        query.UpdateFindPath(100, out s);
        query.EndFindPath(out s);
        NativeArray<PolygonId> slice = new NativeArray<PolygonId>(20, Allocator.Temp);
        query.GetPathResult(slice);

        slice.Dispose();
        query.Dispose();
    }
}

Hi! This is a bug that we've only recently become aware of. We'll fix it soon.

2 Likes

[quote=“adriant”, post:2, topic: 719541]
Hi! This is a bug that we’ve only recently become aware of. We’ll fix it soon.
[/quote]
Hi, I have faced with same problem, has it been fixed in the last version?

I've encountered this issue on 2020.1.5 (or a very similar one) and managed to isolate it in a small scene; since this has either not been fixed or appeared again; and I didn't see any active reports I've created a new one, you can track the progress here.

I am having this in 2021 (the year too)

[quote=“victor_apihtin”, post:5, topic: 719541]
I am having this in 2021 (the year too)
[/quote]
If it’s the same bug as mine it should be fixed depending on the version:
https://issuetracker.unity3d.com/issues/navmeshquerys-beginfindpath-returns-an-argumentexception-when-the-agent-type-id-value-is-negative

Try debugging the agentID that’s giving you trouble, if the value is positive it might be something else.

My error was that Agent Type ID is not what I thought an index in "agents" list, but a hash value.
Trying the number from the navmesh asset itself makes it work fine :)