PathManager - Pathfinding made easy

Simplify pathfinding using my new module, PathManager! It’s a powerful wrapper for SimplePath that gives you full control over your NPCs.

Setup

Get the module from the roblox creator marketplace and place it somewhere in your project. https://create.roblox.com/store/asset/79723965636846/PathManager

Preferably ServerStorage.

local PathManager = require(game.ServerStorage.PathManager)

local npc = workspace.NPC
local goal = workspace.GoalPart

local manager = PathManager.new(npc, goal)

Settings

These can be passed into the PathManager.new() call as a table:

Setting Default Description
visualize false Whether to visualize the path in the workspace.
autoRun true Automatically call Run() when goal is set.
debug false Print debug warnings like path blocked errors.
retrack true Recalculate path every time a waypoint is hit.

API

PathManager.new(character: Model, goal: Vector3 | BasePart, settings: table?)

Creates a new PathManager instance.

local manager = PathManager.new(NPC, Vector3.new(10, 0, 10))

PathManager:Run()

Begins pathfinding towards the set goal.

manager:Run()

PathManager:Stop()

Stops the character’s current path.

manager:Stop()

PathManager:Pause(seconds: number)

Stops the path and resumes after a set delay.

manager:Pause(3)

PathManager:SetGoal(goal: Vector3 | BasePart)

Updates the goal. If autoRun is enabled, it reruns the path.

manager:SetGoal(workspace.NewGoal.Position)

PathManager:SetCallback(eventName: string, callbackFn: (...any) -> ())

Assigns a function to run when an event occurs.

Callback Name Description
OnGoalReached Called when goal is reached
OnBlocked Called when path is blocked
OnError Called when there’s an error
OnWaypointReached Called when a waypoint is reached
OnStopped Called when path is stopped manually
manager:SetCallback("OnGoalReached", function()
	print("I have arrived!")
end)

manager:SetCallback("OnBlocked", function()
	warn("I'm stuck, heeeeelp!!!")
end)

PathManager:GetSimplePath()

Returns the internal SimplePath object.

local sp = manager:GetSimplePath()
print(sp.Status)

If you have any questions or need help using the module, feel free to reply to this post!

8 Likes

Hello, I am having an error with the functions. When I give, for example

self.path:SetCallback("OnBlocked", function()
			warn("im stuck")
		end)

I recive an error saying this

PathManager: Invalid callback name "OnBlocked"