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 8 months ago
- Reactions: 5
- Comments: 19 (16 by maintainers)
added
but still getting error
trying the above solution in
v4.2.stable.official 46dc27791
, I don’t have this error any moreI’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_changed
NavigationServer3D event:Not sure if this is ideal but the mobs load without issue.
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.
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
BasicMap
where processing players locations and classEnemy
who chasing players: BasicMap.gdEnemy.gd
This is multiplayer game and physics management should be controlled from the server, but this is next steps.
What Scony mentioned. You can either wait for the
physics_frame
tick or you can listen to the NavigationServermap_changed
signal 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
await
in_ready()
does not work sometimes so it is better to call_deferred() and thenawait
.Example from the documentation:
@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: