I am having issues with dynamically setting my NavMeshObstacle’s properties in code. Basically what i try to do is autotile my wall sprites, so the the polygon collider will match the sprite physics shape.
I’m now trying to match the shape in the navMeshObstacle but whenever i set the center or size, it is no longer carved in my navMesh, as you can see in the gif.
This is literally all I’m doing after setting the new sprite and recalculating the polygon collider bounds based on sprite physics shape:
PolygonCollider2D p = GetComponentInChildren<PolygonCollider2D>();
_obstacle.center = p.bounds.center;
_obstacle.size = p.bounds.extents;
These are the correct bounds, i set them to the polygon colliders bounds in the inspector and the size matches perfectly. I also tried baking my navmesh again after changing the sprite, but it is VERY slow, not feasible at all in a realtime game scenario, and it also doesn’t work! I’ve also tried turning off/on the carve, and nothing.
I’ve tested it on another object with a navMeshObstacle and setting the size kept the carving, but changing the center removes it as well. I tried replicating this on my wall, but no matter what it removes the carving.
Can anyone help me figure out what’s going on? I’m starting to think it’s a Unity bug since there is no way to recarve or something on the obstacle itself.


