Checking if path possible using one way NodeLink2

  • A* version: [5.2.5]
  • Unity version: [2022.3.42f1]

Hi. I have a question related to checking destination reachability. I am using a multi-layer gridGraph over a large area and many different NodeLink2. Is there a way to write a fast method to check destination reachability, similar to IsPathPossible? Bots use a vision sensor that needs to check the reachability of all visible objects from the bot’s current position to mark objects as interactive. For a mobile project, calculating the path to each object from each bot is an expensive task just to check the path to it. There are at least ten agents in the game (more planned soon), and there are more visible objects that need to be checked for reachability and build paths to them: loot boxes, ammo, weapons, medicine, enemies, etc. in a fairly large area. Is there a way or possibility to write a script for the current latest version of the asset to perform a check that will work quickly and will not use the naive approach of calculating the full path to check if a valid path can be built? I will also attach a visual supplement to the question.

T̶h̶e̶ ̶o̶n̶l̶y̶ ̶a̶l̶t̶e̶r̶n̶a̶t̶i̶v̶e̶ ̶I̶ ̶c̶a̶n̶ ̶t̶h̶i̶n̶k̶ ̶o̶f̶ ̶i̶s̶ ̶̶P̶a̶t̶h̶.̶C̶a̶n̶T̶r̶a̶v̶e̶r̶s̶e̶̶ ̶b̶u̶t̶ ̶a̶s̶ ̶f̶a̶r̶ ̶a̶s̶ ̶p̶e̶r̶f̶o̶r̶m̶a̶n̶c̶e̶ ̶g̶o̶e̶s̶,̶ ̶I̶ ̶w̶o̶u̶l̶d̶n̶’̶t̶ ̶r̶e̶a̶l̶l̶y̶ ̶k̶n̶o̶w̶- I’ll tag @aron_granberg on this to get his insight on the performance complications of these methods and any alternatives.

Crossed out my “answer” as it’s actually incorrect, my apologies!

Hi

This is not possible, I’m afraid.
IsPathPossible uses precalculated information based on connected components (graph theory). But one-way links may confuse it, and it will in most cases treat the one-way link as a two-way link for this purpose.

However, you can make a semi-fast check. Using a MultiTargetPath you can calculate a path from the agent to everything that it needs to reach. Then you can check if each individual path was able to complete or not. The multi target path will be a lot faster than calculating one path for each item.

You’ll probably want to use AstarPath.StartPath here, instead of Seeker.StartMultiTargetPath. To avoid interfering with your agent’s movement.

See MultiTargetPath - A* Pathfinding Project