godot: NavigationServer map query failed from _physics_process
Godot version
4.1.3
System information
Macos
Issue description
getting error/warning on first frame
E 0:00:03:0742 abr.gd:41 @ _physics_process(): NavigationServer map query failed because it was made before first map synchronization.
<C++ Error> Condition "map_update_id == 0" is true. Returning: Vector<Vector3>()
<C++ Source> modules/navigation/nav_map.cpp:119 @ get_path()
<Stack Trace> abr.gd:41 @ _physics_process()
on this code
extends CharacterBody3D
@onready var nav_agent = $NavigationAgent3D
func _physics_process(_delta: float) -> void:
var next_position = nav_agent.get_next_path_position()
var new_velocity = (next_position - global_position).normalized()
nav_agent.velocity = new_velocity
what the right way to implement Navigation path finding?
Steps to reproduce
call get_next_path_position from _physics_process
Minimal reproduction project
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 7
- Comments: 22 (18 by maintainers)
trying the above solution in
v4.2.stable.official 46dc27791, I don’t have this error any moreadded
but still getting error
I’m using Godot v4.2.stable.official 46dc27791 and I’m seeing this issue on a Mac (M1).
I used the workaround suggested by @smix8 here: https://github.com/godotengine/godot/issues/84677#issuecomment-1841014124
Instead of relying on the
physics_frame, I wait for amap_changedNavigationServer3D event:Not sure if this is ideal but the mobs load without issue.
@theromis you very likely need to wait for the navigation to synchronize. For that, you can e.g. wait 1 frame before doing any queries:
await get_tree().physics_frame- the problem with that is, you shouldn’t do it in the_physics_process. Therefore I’d recommend blocking the processing for 1 frame like:Just want to share my solution in case somebody else have the same issue, my actual code a bit more structured, so I have a class
BasicMapwhere processing players locations and classEnemywho chasing players: BasicMap.gdEnemy.gd
This is multiplayer game and physics management should be controlled from the server, but this is next steps.
On Godot master with PR https://github.com/godotengine/godot/pull/84275 you can now query the navigation map iteration id before you do a navigation path query or set an agent target position that may end empty / as an error. The error msg now also only prints one time and only in debug builds to be less spammy. This should all be part of 4.3 dev4 soon if you do not want to build Godot master.
I think this closes the issue but feel free to add if there is still something missing for this issue.
My simple realisation:
But this is a crutch. It would be good to fix this error as it clearly shouldn’t occur under normal conditions.
The navigation has not really changed in that regard. The server sync still happens at the same time as before. So your options are to wait for the physics sync or listen to the NavigationServer map_changed signal.
What Scony mentioned. You can either wait for the
physics_frametick or you can listen to the NavigationServermap_changedsignal to know when a navigation map sync has happened.That errors is because the navigation map has never synchronized at least once. The NavigationServer sync happens on the physics_frame tick.
Using
awaitin_ready()does not work sometimes so it is better to call_deferred() and thenawait.Example from the documentation: