godotengine / godot

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

NavigationMesh takes a long time to bake on gridmap during runtime #58941

Closed SoftDevDanial closed 2 years ago

SoftDevDanial commented 2 years ago

Godot version

4.0-alpha4 , 4.0-alpha1

System information

Windows10

Issue description

Hi,

Im using a gridmap in my NavigationRegion3D with a 37x37 floor. The time taken for the NavigationRegion3D to bake takes [+/-]10 seconds during runtime(run through script). Is this a normal thing to take so long to bake? Before this i had a 13x13 floor and it took [+/-]5 seconds.

image

However, when i create it using a staticbody with a collision body and meshinstance, it takes <1 seconds(i think even less than 0.2 seconds). The staticbody floor has the size of the 13x13 gridmap floor.

Steps to reproduce

  1. Create a 37x37 gridmap floor(this takes roughly 10 sec to bake) or 13x13 gridmap floor(this takes roughly 5 sec to bake)
  2. Attach the gridmap to NavigationRegion3D
  3. Place a Point3d on 1 grid( decent range for better debug)
  4. Create a characterbody3d instance which will navigate to that point
  5. Attach a script to another Point3d or any node should be ok
  6. Add below script to the _ready function
    navigation_region.bake_navigation_mesh()
    time_start = Time.get_unix_time_from_system()
    print("Running navigation mesh bake function at " , time_start)
  7. Connect the NavigationRegion3d._on_navigation_region_3d_bake_finished() to the script and add below script under the function
    func _on_navigation_region_3d_bake_finished():
    time_now = Time.get_unix_time_from_system()
    print("Navigation Mesh has done baking at " , time_now)
    print("Elapsed time - " , time_now - time_start)

Minimal reproduction project

Minimal Reproduction Project.zip

Calinou commented 2 years ago

@SoftDevDanial Please upload a minimal reproduction project to make this easier to troubleshoot.

SoftDevDanial commented 2 years ago

@Calinou I have included the Minimal Reproduction Project

Scony commented 2 years ago

@SoftDevDanial the issue is virtually the same as in #57148 With my proposed approach to fixing it, this issue here can be easily resolved as well. Anyway, it all depends on whether there will be green light from this proposal: https://github.com/godotengine/godot-proposals/issues/3918

SoftDevDanial commented 2 years ago

@Scony So when baking the mesh, it takes each mesh instance in the gridmap and in my case 37x37 mesh instance but when i baked the mesh on a staticbody with 1 meshinstance, no matter how big it is, it wont take a long time since it has only one meshinstance and this happens because the baking is done on a separate thread. Am i correct?

Is there a way to force it to not bake on a seperate thread for now without compiling the godot engine as i just want to see the difference

Scony commented 2 years ago

@SoftDevDanial yes, correct. And regarding not baking on a separate thread - you'd have to prepare geometry beforehand and bake in the editor. Not possible in runtime atm.

SoftDevDanial commented 2 years ago

@Scony Thanks for the clarification! Should i close this issue as you have already raised this issue before?

Scony commented 2 years ago

@SoftDevDanial technically it refers to a slightly different part of the parse_geometry() so I'd recommend to not close this issue.

akien-mga commented 2 years ago

Fixed by #59849.