How to change NavigationPolygonInstance in runtime?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By patrik
:warning: Old Version Published before Godot 3 was released.

How do i change a navpoly in the code during runtime?

I use the 2d demo, navpoly as an example. The following code is expected in the navpoly example to make the sprite stop completly since whole polygon is remove, but it doesn’t.

var navpoly = get_node("Navigation2D/NavigationPolygonInstance").get_navigation_polygon()
navpoly.clear_polygons()
get_node("Navigation2D/NavigationPolygonInstance").set_navigation_polygon(navpoly)

I would like to remove or add parts of the polygon so the path is changed dynamicly.
EDIT: Actually, all changes to the navpoly with the set_navigation_polygon seems to stop the navigation. What am I doing wrong?