PathfindingService Navmesh Not Updating On Runtime?
Asked by
7 years ago Edited 7 years ago
On the wiki reference for PathfindingService (API:Class/PathfindingService), it states that "PathfindingService generates a navigation mesh over all of the parts in the place while a game is running" and "If the geometry of the place changes, for example if a part moves or is created, then the navigation mesh will be recalculated." It also states this on the DevForum post regarding the release of the new pathfinding system: "Dynamic Navigation Mesh generation: The navmesh will automatically regenerate when obstacles move around the world." (Introducing: Roblox Pathfinding)
However, my navmesh is not updating while running the game with the studio "run" button, nor does it seem to update while playing through the normal client.
I have a script that spawns a new brick a second after the game starts running and resizes a premade brick in the Y axis, to make what was previously a jumpable surface too high to be jumped upon. The navmesh does not take these changes into account. (Screenshot)
Why isn't the navmesh updating in real time, even though it is supposed to?
Thanks.
Edit: After some more playing around, I found out that the navmesh only updates with a new call of FindPathAsync of PathfindingService. CheckOcclusionAsync is supposed to check if a path is made invalid, but my implementation doesn't seem to work. Here is my script for my pathfinding:
01 | local pathfinding = game:GetService( "PathfindingService" ) |
03 | local startBrick = workspace.NPC.Torso |
04 | local endBrick = workspace.GoBrick |
05 | local reachedEnd = false |
08 | path = pathfinding:FindPathAsync(startBrick.Position, endBrick.Position) |
09 | waypoints = path:GetWaypoints() |
14 | function drawWaypoints() |
16 | for i = 1 , #waypoints, 1 do |
17 | local marker = game.ReplicatedStorage.WP:Clone() |
18 | marker.Name = "WP" .. i |
19 | marker.Parent = workspace.PathPoints |
20 | marker.Position = waypoints [ i ] .Position |
21 | if waypoints [ i ] .Action = = Enum.PathWaypointAction.Jump then |
22 | marker.BrickColor = BrickColor.new( 255 , 0 , 0 ) |
28 | local chara = workspace.NPC.Humanoid |
31 | for i = 1 , #waypoints, 1 do |
32 | local blocked = path:CheckOcclusionAsync(i) |
37 | chara:MoveTo(waypoints [ i ] .Position) |
40 | if waypoints [ i- 1 ] ~ = nil then |
41 | if waypoints [ i ] .Position.Y > waypoints [ i- 1 ] .Position.Y then |
46 | if (waypoints [ i ] .Action = = Enum.PathWaypointAction.Jump) and (lastWPs) then |
50 | chara.MoveToFinished:Wait() |
55 | while not reachedEnd do |
So it seems that CheckOcclusionAsync is never making blocked ~= -1. The wiki page isn't very helpful for the function. It wants an int start as the parameter, but what exactly is that int? I've been passing it the index of my current waypoint, but that seems to be the wrong assumption.