Agent Parameters: The First Thing to Check
When you create a path with PathfindingService:CreatePath(), you pass an AgentParameters table. If these do not match your NPC's actual size, the path will either fail to compute or route through spaces the NPC cannot physically fit. AgentRadius is the most critical parameter: it defines a cylinder around the agent that must not intersect geometry. Set it to half your NPC's HumanoidRootPart width plus a small buffer (0.5-1 stud). AgentHeight must match or exceed the NPC's actual height including the head. AgentCanJump must be true if your NPC needs to traverse vertical gaps, and AgentCanClimb must be true for TrussParts. If the path returns NoPath status, your agent parameters are likely too large for the environment. Test by temporarily reducing AgentRadius to 1 and checking if the path computes. If it does, the issue is tight spaces in your map, not a pathfinding bug.
- AgentRadius: half the NPC width + 0.5-1 stud buffer
- AgentHeight: NPC full height including head
- AgentCanJump: true if the NPC needs to jump gaps or curbs
- AgentCanClimb: true if TrussParts exist in the path
Path Status: Stop Ignoring the Return Value
After calling Path:ComputeAsync(start, goal), always check Path.Status before using the path. The possible values are Success (path found), NoPath (no valid route exists), and ClosestNoPath (partial path to the nearest reachable point). Most developers only handle Success and ignore the other two, which leaves the NPC standing still with no error or feedback. For NoPath, log the start and end positions and visualize them in Studio to understand why no route exists. Common causes: the goal is inside a wall, the goal is on a different floor with no navigable connection, or the agent is too large for the available space. For ClosestNoPath, you can either move the NPC to the closest reachable point as a fallback or reject the path entirely and try a different goal. Never skip the status check because a failed path returns zero waypoints and your movement logic will silently do nothing.
Handling Blocked Paths and Recomputation
Once a path is computed, it represents the state of the world at that moment. If a door closes, another NPC moves into the way, or the player moves, the path may become blocked. Connect to Path.Blocked to detect when a waypoint becomes unreachable after computation. In the handler, recompute the path from the NPC's current position to the goal. Without this handler, the NPC will walk to the blocked waypoint and stand there forever. Recompute the path on a timer as well (every 1-2 seconds during active pursuit) to account for moving targets. Be careful not to recompute too frequently because ComputeAsync is not free. Debounce recomputation by checking if the target has moved more than a threshold distance (5-10 studs) since the last computation before recomputing. For NPCs chasing a player, recompute only when the player has moved significantly or when a blocked event fires.
