[Update] November 15, 2024
Hello Creators,
As you know, pathfinding is a crucial component to enable rich NPC behavior that enhances the overall user experience. Over the past few years, we’ve received your reports on the many quality issues related to the Pathfinding service. Similar to the recent improvements in memory and performance, we have focused on making significant improvements to pathfinding quality this year.
We identified three major issues where fixes would have the greatest impact: poor quality path generation, paths not properly accounting for agent size / environment features, and paths failing to generate (properly or at all) due to poor Navmesh generation.
Today, we are releasing an opt-in algorithm update that focuses on all three of these pathfinding quality issues (see below for examples).
Based on community feedback, we’re also reintroducing the return of partial paths when the full path is not found. Partial paths are best effort and may not always return the optimal partial path.
While this new behavior should fix many problems, we are releasing it as opt-in and relying on your feedback so that we can make improvements before making this the default via 3 phase rollout over the course of 2025. We recommend you try it in a test place first to confirm you are happy with the new behavior before publishing it in your experience.
We do not anticipate any memory or compute time regressions as a result of these fixes and enhancements, but please reach out or reply below if you observe any performance issues.
How to enable the new Pathfinding algorithm and fixes
In order to not disrupt live experiences, we’re providing three options for this property:.
- Default: This will use the production algorithm for now. Once we move to opt-out in mid 2025, this would use the new pathfinding algorithm going forward.
- Disabled: This will use the production algorithm even after we update the default behavior
- Enabled: This will opt your experience into the new pathfinding algorithm and fixes.
To enable this algorithm, click on Workspace → Properties → PathfindingUseImprovedSearch as shown below.
Issues addressed by this update: before and after
Path Zig-Zagging
View details
Pathfinding service generates zig zag paths when the straight path is available. Many reported examples.
Before:
After:
Additional examples
Path Quality: Path too close to the wall cause agent to get stuck
Paths not using Agent’s size
View details
PathfindingService doesn't always use agent params; makes service unusable for large characters
Before:
After:
Path going through walls
View details
Similar Issues we believe this should fix:
- Pathfinding trying to go through walls
- PathfindingService computes paths through areas too small for agents to fit through
- Help with the pathfinding in my map
Before:
After:
Pathfinding giving bad paths in terrain due to bad navmesh
View details
Engine Bug: Pathfinding service is arbitrarily inable to path some terrain - #2 by Markaaron
Before:
After:
Before:
After:
Returning Partial Paths
View details
PathFindingService Giving Closest Path To Object - #15 by focasds
Before (No Path):
After (Partial Path up to the blocked entrance):
How to get partial path results from the Pathfinding response
To get partial path results, please make sure to select PathfindingUseImprovedSearch property > Enabled. Partial paths can only be returned when PathfindingUseImprovedSearch is Enabled.
In order to maintain backwards compatibility, we are introducing PathSettings
in agentParameters
. When calling the CreatePath(agentParameters)
API, you can specify if you need a partial path by setting PathSettings.SupportPartialPath = true
as shown in the example below (the default will be false
). If PathSettings.SupportPartialPath
is true
and computeAsync
only finds a partial path, then instead of setting Path.Status
to Enum.PathStatus.NoPath
, it will set Path.Status to Enum.PathStatus.ClosestNoPath
. If PathSettings.SupportPartialPath
is false
or not set in the agentParameters
, then PathStatus
will only return NoPath
or Success
depending on whether the path to the destination was found. Please see the code example below.
local path = game.PathfindingService:CreatePath({
AgentRadius = 2,
AgentHeight = 5,
AgentCanJump = true,
Costs = {
Water = 20
},
PathSettings = {
SupportPartialPath = true
}
})
-- Compute the path
local success, errorMessage = pcall(function()
path:ComputeAsync(startPosition, finishPosition)
end)
-- Confirm the computation was successful or it returned partial path
if success and ( path.Status == Enum.PathStatus.Success or path.Status == Enum.PathStatus.ClosestNoPath) then
--- custom code for movement
end
Acknowledgements
Please try out this update and let us know your feedback! We want to continue investing in improvements to Pathfinding and other aspects of NPCs. A huge thank you to the entire community for filing reports, sharing test scenes, and following up with us. In particular, we would like to acknowledge @xChris_vC and @Halferee for providing initial feedback on these updates, and a special thanks to @xChris_vC for the awesome maze test that truly pushed the boundaries of our algorithm during testing.
– @WatisInTheName, @oldmannt, @Bloxsometa and the Movement and Pathfinding team