Tilemap navigation breaks when I try to reparent navigation2D node.

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

(Update)

I have project with several different separate maps, each of them has Navigation2D node with Tilemap as a child, and tiles have Navpolygons attached to them.

When i just load the scene from disk and instance it like that:

new_scene = ResourceLoader.load(path).instance()

Everything is fine, and get_simple_path on enemies works correctly.
When player leaves the scene it is removed from the tree and saved in the dictionary so i can load it when player returns to it.
And this works correctly for everything( like positions of enemies, items player picked up etc )
But get_simple_path in enemies returns empty array, like navigation polygon no longer exists.
I tried to figure out what exactly happens and honestly i do not quite get it but if i write code like this

   new_scene = ResourceLoader.load(path).instance()
   get_tree().get_root().get_node("root/level").add_child(new_scene)
   var child=get_tree().get_root().get_node("root/level/room")
   var parent=get_tree().get_root().get_node("root/level")
   parent.remove_child(child)
   parent.add_child(child)

Basically if just remove my level from tree and immediately add it again it will break navigation.
Is there something i don’t understand about how tilemap navigation works?
If use just regular Navpolygon directly in the level it does not disappear of course.

(Update)
I fiddled a little more and added a button that deletes random cell in the TileMap.
If you do that than navigation starts to work, but not really, it is like only Half of the navigation polygon works, but if you delete more cells it sometimes starts to work completely. It is easier to understand if you see the project attached.

Maybe that’s a bug, do you have a minimal repro project?
Do you see any error in the system console?

Zylann | 2018-01-08 13:52

Here:
https://drive.google.com/open?id=1Khw3jkoK68sATFBlzdQMsTJUELg4CWUP
A little minimalistic but it shows the issue:
If you just load the room initially and click anywhere it gets points with get_simple path
but if you then “reload” room get_simple path will always return empty array.

Maybe something is happening in navigation or tileset on _enter_tree() or _exit_tree()?

gromhunter | 2018-01-09 11:17

OK, i searched for similar issues and they all not quite what is happening to me.
It is like Navigation polygon just disappears.

Only clue, after some testing is that if NavPolygons overlap in a weird way, (like if i extend it slightly beyond tile borders) get_simple path will also return empty array, but only with some coordinates combinations, with some it will still return path.

Everything would be much easier if i somehow would be able to Visualize navigation polygon, but from what i can understand you really cannot.

Sadly i cannot really read source code that well but i really want to know what is happening, like is it a bug? Or am i just stupid?

I also tried for the heck of it to do the same thing in 3.0 and same thing happens.

Here is minimal working example(not in 3.0):
https://github.com/Gromhunter/nav_test

gromhunter | 2018-01-12 12:23

I have the exact same issue in my project. This only seems to affect NavPolygons in TileMaps.

authentication | 2018-01-15 08:27

You should post your issue on Github.
It sounds similar to keep Navigation with TileMap up to date · Issue #11077 · godotengine/godot · GitHub though, but the repro is different

Zylann | 2018-01-15 20:21

I went ahead and made a github issue.

You can find it here:

TileMap with NavigationPolygons returns incorrect path after exiting and re-entering tree. · Issue #15767 · godotengine/godot · GitHub

authentication | 2018-01-16 04:17

Thanks, i was going to submit an issue eventually, but just decided to wait a little to see if anyone had the same problem.

gromhunter | 2018-01-17 11:41