
Nav Mesh Areas
In the previous section, we talked about how not all parts of the navigable area of the map are created equal. If there is a zone that it is considered dangerous, the AI should avoid it. Unreal's built-in navigation system is able to handle these different areas by using costs. This means that the AI will evaluate the path to take by summing all the costs along the path, and it will select the one with the minimal cost.
Also, it is worth specifying that there are two types of costs. For each area, there is an initial cost for entering (or leaving) the area and a cost for traversing the area. Let's look at a couple of examples to clarify the difference between the two.
Imagine that there is a forest, but at each entrance of the forest, the AI needs to pay a toll to the indigenous living in the forest. However, once inside, the AI can move freely, as if they were outside the forest. In this case, entering the forest has a cost, but once inside, there is no cost to pay. As a result, when the AI needs to evaluate whether to traverse the forest or not, it depends on whether there is another way to go and how long it would take them to do so.
Now, imagine that there is an area with poison gas instead. In this second scenario, the cost for entering the area might be zero, but the cost for traversing it is high. In fact, the longer the AI stays in the area, the more health it loses. Whether it is worth entering or not only depends on whether there is an alternative way and how long that alternative way will take to traverse (like in the previous case), but also how long, once entered, the AI needs to traverse the area.
In Unreal, costs are specified inside the class. If you click on a Nav Modifier Volume, you will notice that you need to specify an Area Class, as shown in the following screenshot:

As you may have guessed, the default value is NavArea_Null, which has an infinite cost for entering, resulting in the AI never going into that area. The Navigation system is smart enough to not even bother generating that area, and treats it as a non-navigable area.
However, you can change the Area Class. By default, you will be able to access the following Area Classes:
- NavArea_Default: This is the default area that is generated. It is useful to have it as a modifier in case you want to have more than one of these modifiers in the same spot.
- NavArea_LowHeight: This indicates that the area is not suitable for every agent, since the height is reduced (for example, in the case of a ventilation tunnel, not all the agents can fit/crouch).
- NavArea_Null: This makes the area non-navigable for all the agents.
- NavArea_Obstacle: This assigns a higher cost to the area, so the agent will want to avoid it:

However, you can extend the list of the different areas (and potentially add more functionalities) by extending the NavArea Class. Let's see how we can do this, both in Blueprint and C++. Of course, as we did in the previous chapter, we are going to create a new folder named Chapter3/Navigation, in which we will place all our code.