-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Needs documentation: NavigationServer will only update after 1 physics frame #57022
Comments
Can't run and test mono builds but here are a few things. The NavigationServer is active by default as soon as it is created by Godot, no need to set it active again. If a Map is created through NavigationServer API alone it needs to be created / registered and set activated afterward. Any change like registering a map, a region or an agent, changing their transform ... takes time to sync as the NavigationServer runs on a different thread. Don't expect changes to be in effect immediately or a path to return on the same frame you setup all the regions and maps. You need to wait at least 1 physics tick for the NavigationServer sync and queue flush before changes can take place. If possible please test again and verify. I think it is not a bug but a setup, documentation and expectation issue. |
Thx for the reply! |
var navmesh : NavigationMesh
func _ready():
# use call deferred to make sure the entire SceneTree Nodes are setup
# else if yield on 'physics_frame' in a _ready() sceneload might get stuck
call_deferred("setup")
func setup():
navmesh = NavigationMesh.new()
var vertices : PoolVector3Array = PoolVector3Array([Vector3(0,0,0), Vector3(9.0,0,0), Vector3(0,0,9.0)])
navmesh.set_vertices(vertices)
var polygon : PoolIntArray = PoolIntArray([0, 1, 2])
navmesh.add_polygon(polygon)
var map : RID = NavigationServer.map_create()
var region : RID = NavigationServer.region_create()
NavigationServer.map_set_up(map, Vector3.UP)
NavigationServer.map_set_active(map, true)
NavigationServer.region_set_transform(region, Transform())
NavigationServer.region_set_navmesh(region, navmesh)
NavigationServer.region_set_map(region, map)
# wait for NavigationServer sync to adapt to changes made
yield(get_tree(),"physics_frame")
var is_active : bool = NavigationServer.map_is_active(map)
print("Is active: %s" % is_active)
var path : PoolVector3Array = NavigationServer.map_get_path(map, Vector3(0.1, 0.0, 0.1), Vector3(1.0, 0.0, 1.0), true)
print("Found waypoints:")
print(path) |
@Xyotic |
Will try it this weekend |
@smix8 waiting for the physics frame to end did the trick! For anyone curious, this it how it would look in C# NavigationMesh navmesh;
public override void _Ready()
{
CallDeferred(nameof(Setup));
}
private async void Setup()
{
navmesh = new NavigationMesh();
navmesh.Vertices = new Vector3[]
{
new Vector3(0,0,0),
new Vector3(9,0,0),
new Vector3(0,0,9),
};
navmesh.AddPolygon(new int[] { 0, 1, 2 });
var map = NavigationServer.MapCreate();
var region1 = NavigationServer.RegionCreate();
NavigationServer.MapSetUp(map, Vector3.Up);
NavigationServer.MapSetActive(map, true);
NavigationServer.RegionSetTransform(region1, Transform.Identity);
NavigationServer.RegionSetNavmesh(region1, navmesh);
NavigationServer.RegionSetMap(region1, map);
await ToSignal(GetTree(), "physics_frame");
var result = NavigationServer.MapGetPath(map, new Vector3(0.1f, 0, 0.1f), new Vector3(1f, 0, 1f), true);
GD.Print("Found waypoints: " + result.Length);
foreach (var r in result) GD.Print(r);
} |
If this is a documentation issue, it shouldn't be closed before documentation is updated. |
Godot version
Godot 3.5-beta1_mono
System information
Windows 10, GLES3, RTX2080
Issue description
Edit: @smix8 noticed the issue was me not waiting for the physics frame to end.
See the solution in the comments. Changing the subject to "Needs documentation".
Setting a NavigationServer map to active via .MapSetActive() does not have any effect.
.MapIsActive() will always return false.
I used a pretty simple setup using C#:
Steps to reproduce
Run the MRP in Godot 3.5 beta mono build.
Minimal reproduction project
NavigationServerTest.zip
The text was updated successfully, but these errors were encountered: