Facepunch / sbox-issues

175 stars 12 forks source link

Navmesh.GetRandomPoint/GetClosestPoint Not Working on start #5909

Open SwagAccount opened 1 month ago

SwagAccount commented 1 month ago

Describe the bug

I am trying to use GetRandomPoint and GetClosestEdge, but it just isn't working with any map.

The navmesh is generated and looks correct.

To Reproduce

  1. Use GetRandomPoint and GetClosestEdge

Expected behavior

Returning random points on navmesh and find closest edge

Media/Files

https://github.com/Softsplit/sandbox-classic/blob/Testing/Code/AI/CoverFinder.cs

Additional context

No response

SwagAccount commented 1 month ago

image

Copied the function to my code and this just doesn't log at all

SwagAccount commented 1 month ago

image Logging the position 2 shows that the points being checked are perfectly within range of getclosestpoint, meaning that is probably what is wrong here.

SwagAccount commented 1 month ago

Okay so figured it out, still stupid, but I figured it out.

Even though, as of now, I'm awaiting the generation on start the nav mesh hasn't generated/loaded yet after the await (fix works even without awaiting this).

All I needed to do to fix it was to add a Task.Frame() after the generation.

Feels silly.

P.S. This is just a work around for not being able to access the actual mesh data which doesn't allow me to grab all edges, instead I have to literally throw shit at a wall to find as many edges as possible.