Documentation

Unity Engine


User Manual

Script Reference

Unity Engine


SetAreaCost(int, float)

Sets the cost for finding path over geometry of the area type on all agents.
Read time 1 minuteLast updated 13 days ago

Definition

  • Type: Method
  • Namespace: UnityEngine.AI
  • Assembly: UnityEngine.AIModule
public static void SetAreaCost(int areaIndex, float cost)

Parameters

areaIndex

Index of the area to set.

cost

New cost.

Remarks

This will replace any custom area costs on all agents, and set the default cost for new agents that are created after calling the function. The cost must be larger than 1.0.
Use NavMesh.GetAreaFromName to find the area index based on the name of the NavMesh area type.
Additional Resources: Areas and Costs

Examples

using UnityEngine;using UnityEngine.AI;public class ToggleWaterCost : MonoBehaviour{ void Update() { if (Input.anyKeyDown) { // Make the water area 10x more costly to traverse. NavMesh.SetAreaCost(NavMesh.GetAreaFromName("water"), 10.0f); } }}