- Home /
This question was
closed Jul 19, 2019 at 10:03 PM by
CCnockaert for the following reason:
The question is answered, right answer was accepted
Question by
CCnockaert · Jul 19, 2019 at 08:59 PM ·
navmeshnavmeshagentagent
Change AgentType at runtime.
Hello,
I want to change the agentType of a NavMesh Agent component at runtime, I know that it's easy to do with :
agent.agenTypeID = x;
But I'm looking for a way to change it with a string reference, not an ID. ( because if I delete an AgentType later then IDs will change for each agent type too ).
Do you know any way to do that ?
EDIT :
I found a solution
public static class AgentTypeID
{
public static int GetAgenTypeIDByName(string agentTypeName)
{
int count = NavMesh.GetSettingsCount();
string[] agentTypeNames = new string[count + 2];
for (var i = 0; i < count; i++)
{
int id = NavMesh.GetSettingsByIndex(i).agentTypeID;
string name = NavMesh.GetSettingsNameFromID(id);
if(name == agentTypeName)
{
return id;
}
}
return -1;
}
}
Comment
Follow this Question
Related Questions
Disable and Enable NavMesh Agent Unable to Move to Destination 1 Answer
Is it possible to store NavMeshAgents paths and assign them to other NavMeshAgents later? 1 Answer
Multiple agent types problem - NavMesh 0 Answers
NavMesh does not working... 0 Answers
Reasons an NavMesh Agent.isStopped might be set to True? 0 Answers