There are destructible and indestructible objects on the map I created with Tilemap, and I create a walkable area (bake) for my enemy object using the information I found on the internet and the Navmesh packages for 2D games. However, the problem is that after my player destroys breakable objects (Tilemap grid cell), the enemy object still perceives those areas as unwalkable. I'm wondering how I can update the navmesh for the enemy again while the game is running.

I found videos and information on how to do this in 3D games, it looks pretty simple. But I couldn't find anything for 2D games.

Note: I'm using Unity.

  • 1
    \$\begingroup\$ What tools are you using? Engine? Frameworks? \$\endgroup\$
    – Theraot
    Jan 9, 2022 at 2:24
  • \$\begingroup\$ I am using Unity. I am not using any Framework. I'm asking because I couldn't find or overlook such a Framework. \$\endgroup\$
    – gunza
    Jan 9, 2022 at 4:01

1 Answer 1


I found a solution. First of all, download the package in the link and put it in unity. (required for 2D games)


Then you can follow how to do it from the link below: (Do what is explained up to the GEOMETRY OPTIONS heading.)


Finally, create a script for your object named "NavMesh" and write the following code. Thus, if your map objects disappear or move during the game, that free space will be recalculated and become a walkable area.

 using UnityEngine;
 using UnityEngine.AI;

 public class Runtime : MonoBehaviour
public NavMeshSurface2d Surface2D;

void LateUpdate()

Note: Don't forget to assign the NavMeshSurface2d component to the Runtime script.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .