[Solved] What kind of Pathfinding would you recommend for a Restaurant Simulation game?

I am developing a top-down perspective restaurant management simulation.
There are 3 different NPCs: Barista, Waiter, and Customer.
Each one avoids different areas, and I use NavmeshCut for these avoidances.
However, sometimes the pathfinding algorithm fails to find a route, and the NPC stands still. I think there are issues both related to and unrelated to NavmeshCut.

If you were making such a game, what kind of graph would you use? How would you dynamically cover the areas that NPCs need to avoid?

When looking at the image above, we can see that the barista is not going where they should, the console continuously displays ‘path failed,’ and the order ready state on the right side remains in pathfinding. The Order Ready State is a condition I created to understand if there is an error in my code and to see where the barista is getting stuck. If this state remains in pathfinding, it indicates that the barista is not going where they are supposed to.

However, the problem doesn’t end there. As you may notice, the barista is not even attempting to go where they should. To determine whether any NPC has arrived at a location, I use the following method:

using Pathfinding;
public static class Utility
{
    public static bool HasArrived(AIPath AI)
    {
        AI.SearchPath();
        if (AI.pathPending && AI.reachedDestination) { return true; }
        return false;
    }
}

What kind of pathfinding should I implement to prevent issues like this or directly for such games?

Hi

That error message happens if you call ai.SearchPath while it is already calculating a path. If you for example call it every frame, then the agent will never have enough time to calculate its path, and will just stand there.

Also. You forgot an ! on this line:

if (!AI.pathPending && AI.reachedDestination) { return true; }

(though if you use the new FollowerEntity component, you don’t need the pathPending part)

1 Like

Thank you very much for your response, the issue seems to be resolved but for some reason, I can’t fully test it.

Unity suddenly freezes and doesn’t respond at all. I don’t think this problem is caused by pathfinding, but I want to ask you as well, in what situations could pathfinding cause the application to freeze?

Sounds like you have an infinite loop somewhere.

1 Like

The issue was caused by constantly running ‘SearchPath()’.

I decided not to run this in a loop and tested it, but this time, some tasks were immediately considered completed.

To address this, I ran ‘SearchPath()’ once before entering the loop, and the problem was completely resolved.

using Pathfinding;
public static class Utility
{
    public static bool HasArrived(AIPath AI)
    {
        if (!AI.pathPending && AI.reachedDestination) { return true; }
        return false;
    }
}
AIPath.SearchPath();
        while (!Utility.HasArrived(AIPath))
        {
            InitialState = BaristaPreparingState.Pathfinding;
            DebugSystem.Log(DebugLV.Verbose, "Pathfinding in progress...");
            yield return null;
        }