Skip to content
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

2D Runtime-Baked Navigation Mesh Not Working with Agent #92003

Closed
marcol1 opened this issue May 16, 2024 · 5 comments
Closed

2D Runtime-Baked Navigation Mesh Not Working with Agent #92003

marcol1 opened this issue May 16, 2024 · 5 comments

Comments

@marcol1
Copy link

marcol1 commented May 16, 2024

Tested versions

v4.2.2.stable.official [15073af]

System information

Godot v4.2.2.stable - Windows 10.0.22631 - Vulkan (Forward+) - dedicated NVIDIA GeForce RTX 4070 Laptop GPU (NVIDIA; 31.0.15.3210) - 13th Gen Intel(R) Core(TM) i7-13700HX (24 Threads)

Issue description

I have created a navigation mesh at runtime using the builtin functions. However, my navigation agents - who work with premade navmeshes, but not the runtime-baked ones - appear to not be recognizing these navmeshes, and just path to their global_position and stand in place.

I've tried the following:

  • Adding the regions manually to a new navigation map, and adding the agent to this navigation map.
  • I've checked the navigation layers of both the agent & the region.
  • I've checked that the agent, map, and region are all active.
  • I've attempted to create a path using NavigationServer2D, which fails as well.

It's possible this is my error, something small in the code. However, I think even if there's something missing (and I made a mistake), I'd like to propose we make adjustments to the documentation to provide an example of how to get this to work, since I personally found it unintuitive.

I have attached a reproduction project to assist. Thanks!

Steps to reproduce

Attached in project.

Minimal reproduction project (MRP)

Pathing Test Project.zip

@smix8
Copy link
Contributor

smix8 commented May 16, 2024

A NavigationRegion node is a functionality bundle that does a lot of unasked stuff automatically for users. E.g. setting the changed navigation mesh after the bake on both the node and the server region as an update.

When you parse and bake navigation mesh with the NavigationServer functions you do exactly only that, and not a single step extra. So in this case you need to both manually update your node or server region (if you update the node it will update the server region).

The server sync also happens on the physics process, not normal process so those awaits in script should switch to physics process else those function might "miss" the sync and query an empty map.

@marcol1
Copy link
Author

marcol1 commented May 16, 2024

Hey @smix8, thanks for the quick response

Any high-level guidance on how I might accomplish this?

Also, any objections to having an example of this in the documentation? I think registering baked navmeshes with agents at runtime is a common use case, especially in games with procedural maps.

@smix8
Copy link
Contributor

smix8 commented May 17, 2024

Not sure what you are missing, if you updated the navigation mesh you set it again on the region, either on the NavigationRegion node or directly on the NavigationServer region.

Examples can be found in the navigation mesh documentation here

The multi-agent page has also a long script example how to create everything with the NavigationServer API from scratch here

@marcol1
Copy link
Author

marcol1 commented May 18, 2024

Sounds good - I'll see if I can figure it out using those links, thanks!

@marcol1 marcol1 closed this as completed May 18, 2024
@marcol1
Copy link
Author

marcol1 commented May 18, 2024

@smix8 it looks like I just had to set the navigation_polygon after rebaking it, thanks. In my opinion, this is unintuitive, any chance we could add this to the docs, or a clearer spot in the docs? Maybe the docstring for navigation_polygon could say that it does not register rebakes?

From an external perspective, I'd interpret the NavigationPolygon to be a reference, and whenever it changes, the region would register the change.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants