godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.99k stars 21.16k forks source link

Navigation Region 3D Crashes the engine when baking a large Navigation Region 3D #79398

Closed TKHDev21 closed 1 year ago

TKHDev21 commented 1 year ago

Godot version

v4.1.1.rc1.official [e709ad4d6]

System information

Godot v4.1.1.rc1 - Windows 10.0.19045 - Vulkan (Compatibility) - GeForce GT 630M () - Intel(R) Core(TM) i5-3210M CPU @ 2.50GHz (4 Threads)

Issue description

When adding a Navigation region 3D and baking it ( large area ) the engine crashes

Steps to reproduce

In the project, Ignore all of the scenes except the " Obunga ( Enemy scene) " and "park_map" and in the "park_map " scene you will see a node containing children called "Park" in this node you can find the navigation region 3D node, and yeah thats it

Minimal reproduction project

Nextbot's engine.zip

smix8 commented 1 year ago

It is crashing because you are trying to bake with a cell_size so small that it requires 25+ million voxels to cover that single source mesh that you scaled by x4400.

Large, empty planes are the worst for bake performance because the algorithm needs to create a single, gigantic layer of voxel cells that can run suddenly into both int and memory limits. This is an old issue that was already closed as there is little Godot can do about it or predict this situation. The crash is caused by the third-party ReCast Library, that is doing the baking.

E.g. I can bake 2-3 rapid times before it crashes for me. If I wait enough after each bake so both Godot and ReCast can clear memory I can bake all day. Weak hardware might not be able to manage such a large mesh and geometry and you will need to increase your cell sizes or split your scene into smaller sections.

You are also using the default watershed algorithm which is detail-focused and the most expensive of the 3 available. You can switch the bake algo to e.g. something cheaper like monotone or layers if you don't need that much detail.

I would recommend slicing the size of your level into more manageable sections because even if the baking works the resulting navigation mesh is so large that the pathfinding performance will suffer.

TKHDev21 commented 1 year ago

well, yeah but idk the navigation region seems to not work, because of the enemy , it can't move, idk if there is any problem with the code , the only reason I posted this post because of this problem (enemy not moving) i followed a tutorial and it worked fine for him, but maybe the problem is with the navigation agent 3D node, I don't really know, if you want, you can check the project

smix8 commented 1 year ago

You are using a CharacterBody3D node in _process() function. You need to use _physics_process() function for physics based nodes like that.

The current agent script sets the target_position every frame. This resets the agent path every frame making the agent dangle in place.

You can find a fully working script example for a NavigationAgent3D based on a CharacterBody3D node here in the documentation as a starting point.

TKHDev21 commented 1 year ago

Sorry to bother you, and btw thanks!, even tho the enemy isn't moving because it doesn't know what is the target, where should i add the target?

smix8 commented 1 year ago

You can set the target_poisition after waiting for the navigation map sync. The NavigationServer will sync the map after the next physics_frame sou you can try to await that. If you do not wait for the sync the navigation map will be empty and the returned path will be empty as well.

TKHDev21 commented 1 year ago

What do you mean by "Navigation map sync" ? also sorry to bother you with all of those questions, what i want is to set the player as the target but idk in wich line of code

smix8 commented 1 year ago

https://docs.godotengine.org/en/latest/tutorials/navigation/navigation_using_navigationservers.html#threading-and-synchronization

https://docs.godotengine.org/en/latest/tutorials/navigation/navigation_using_navigationservers.html#waiting-for-synchronization

TKHDev21 commented 1 year ago

Im sorry to say that lol, but i dont understand the godot docs, i'm so sorry to bother you , but is there any way that you can tell me a shortcut for this problem?? Im really confused because the guy who made the tutorial that i followed didnt have this problem even tho he used "_process(delta)" and made the whole script basicly the "Navigation sync" is done.

smix8 commented 1 year ago

A tutorial that teaches you to use _process() instead of _physics_process() for a CharacterBody3D movement is incompetent.

Use the official documentation tutorials and examples to create a basic, small test scene. Confirm that everything is working. Start to build your more complex project from there.

TKHDev21 commented 1 year ago

its ok, anyways, I'm really confused about the navigation thing, even after i made the sync thing, the enemy still can't move, because I didn't set the target to the player, my question is : How can i set the player as a target?

AThousandShips commented 1 year ago

For support questions and help please first turn to the other community channels, this is for bug reporting, not a help desk.

Please take this part elsewhere, as it is not a bug from the conversation previously

TKHDev21 commented 1 year ago

Oh, I didn't know

smix8 commented 1 year ago

Can be closed because there is nothing actionable here.