Creating and configuring an agent description from code
All Nav3DAgentDescription parameters configured in the description inspector can also be configured from your code.
To do this, you need to create a variable of type Nav3DAgentDescription
, then apply it to the agent. The correct way to create a description is to refer to the Nav3DAgentDescription.DefaultDescription
property.
After setting the desired parameters in the code, you need to set the description instance to the agent.
If your description contains parameters whose value is configured to be randomly generated, then before setting the description, the agent needs to get a variant of the description with generated parameters. The correct way to get a description instance to set to an agent is to use the Nav3DAgentDescription.GetDescriptionVariant()
method. Calling this method guarantees the creation of a separate instance of the description, taking into account the generated parameters. We recommend that you always use the GetDescriptionVariant()
method to set the description for an agent via code.
void ConfigureAgentDescription()
{
Nav3DAgent myAgent = GetComponent();
//create Nav3DAgentDescription instance with default parameters
Nav3DAgentDescription myDescription = Nav3DAgentDescription.DefaultDescription;
//set the parameters you want
myDescription.Radius = 1.2f;
myDescription.MotionNavigationType = MotionNavigationType.LOCAL;
//apply the description to an agent
myAgent.SetDescription(myDescription.GetDescriptionVariant());
}