Newbie to pathfinding, need help, waypoints don't get created

I basically took one of the starting templates and attempted to modify it to have a constantly pathfinding NPC.

Why does this constantly return no waypoints?

There are no errors in console.

local PathfindingService = game:GetService("PathfindingService")
local PATROL_DELAY = 1

local enemy = script.Parent
local humanoid = enemy.Humanoid
local humanoidRootPart = enemy.HumanoidRootPart
 
while wait(PATROL_DELAY) do
	local currentDestination = workspace.hallowCore
	
	-- Make variables for the start and end of the path
	local startingPosition = humanoidRootPart.Position
	local goalPosition = currentDestination.Position
	
	-- Find a path to the enemy's current destination
	local path = PathfindingService:FindPathAsync(startingPosition, goalPosition)
	local waypoints = path:GetWaypoints()
	
	-- Loop through all of the waypoints in the path
	for waypointIndex, waypoint in pairs(waypoints) do
		print(waypoint.Position)
		local part = Instance.new("Part")
		part.Position = waypoint.Position
		part.Size = Vector3.new(1, 1, 1)
		part.Anchored = true
		part.Parent = game.Workspace
		
		local waypointPosition = waypoint.Position
		-- Make the humanoid move to the current waypoint
		humanoid:MoveTo(waypointPosition)
		-- Wait until the humanoid has reached its target
		humanoid.MoveToFinished:Wait()
	end	
end

So path:GetWaypoints() is returning an empty table?

Does printing path.Status print Success, ClosestNoPath, or ClosestOutOfRange?

1 Like

Yes.

It prints Enum.PathStatus.NoPath.

Weird issue, doesn’t make sense at all. Have you tried turning on the navigation mesh to see what pathfinding in your world would look like?

1 Like

I have, yes. It appears as though the navmesh is fine.

Is it possible that the brick is too far away?

So despite the navmesh being valid, the pathfinder couldn’t seem to find a valid path through the viable navmesh. I solved it by placing a dud brick for it to seek instead of the actual target. :confused:

1 Like

If the finish position was too far from the start position, then the path’s status would be ClosestOutOfRange.

Would you mind providing the place file where this issue is occurring so I can try to find a solution?

ClosestOutOfRange is deprecated. FindPathAsync() does not limit the range of the path.

Not sure if this is your case, but path requests could fail if either start and/or end locations are too far from the navmesh.
If you have a repro place I could investigate this further.

3 Likes

I can see about making a repro.

I think the issue was that I wanted the NPC to pathfind to a large ball’s position, which isn’t exactly possible cause the center is unreachable (if that makes sense).

1 Like

Ah, path finding, my favorite topic! Where are the start and goal positions being set to relative to the ground and nearby objects when you don’t use a proxy part? I’ve gotten this error when the points are too high or too close to a Mesh with a weird invisible collision mesh.

It could potentially be that the target part of the pathfinding was considered to be an obstacle so the path was returning invalid – although that means that the returned Enum might be different. Oh well. Pleased that you found a solution anyway :wink:

1 Like

A sphere about 5 studs off the ground, reachable by a set of stairs. Presumably the sphere was too big though.

Ah yes, both the height and sphere were probably issues. I probably should have read a bit more carefully, as I see you already mentioned that as a possibility. I’m a simple man: I see a pathfinding topic, and I post! Even if it is already solved… :stuck_out_tongue: