Ability to customize collision check

I am using your A* Pro package with Rotorz Tile System (RTS). One feature that RTS has is the ability to have most of your tiles be on a procedural mesh, that is, they all have a single backing GameObject. In order to use A*, you have to force RTS to generate a collider (and GO) for each tile. That adds, well, squillions of extra, useless GOs to the scene.

However, even the procedural tiles are backed by a Serialized Object which contains info about each tile, including various user flags, and a ‘solid’ flag that can be used to test whether or not a tile is present at that (row,col) location.

It was more expedient for me to add a ‘TileSystem’ ColliderType to Base.cs and add some code to the Check() method which checks the ‘solid’ flag at that position. This works quite well for the grid generator (most appropriate for a 2D tile system). But it means that I have to re-add this code for every update you create.

So here’s a generic suggestion: Add a ‘UserDefined’ ColliderType to Base.cs, and two serialized fields visible in the editor:

CustomCheckTarget - drag-in a GameObject target
CustomCheckMethod - type in the name of a method to call.

Then if Check() found that the ‘type’ is UserDefined, it’d check to see if the fields are populated, then invoke CustomCheck with position, finalradius, and mask. The method would return true if the location wasn’t blocked or false if it is blocked.

Obviously that’s just a sketchy way of describing the idea and there’s probably a better way to do this in the context of your system - but it ought to be clear what’s intended. The upside is that A* can support any sort of variant setup this way, by allowing the passable/unpassable state of a location to be outsourced. And that can be done without the user having to write custom grid generators. Maybe a delegate scheme would be better?

jeff@benigngames.com

Hi

The easiest way is to override the grid graph. So you would create a new file with something like this:

public class MyGridGraph : GridGraph {
     public override void UpdateNodePositionCollision ( GridNode node, int x, int z, bool resetPenalty = true ) {
         // Do all the normal stuff
         base.UpdateNodePositionCollision ( node, x, z, resetPenalty );
         node.Walkable = MyCustomCollisionCheck ();
  
         // Just a line that needs to be here for graph updates to function correctly
         node.WalkableErosion = node.Walkable;
     }
}

Then you can create a graph of type MyGridGraph instead of GridGraph in the A* inspector.

PS: Sorry for the late answer

Hey I was away on vacation but I’m both happy to see this and appalled that I didn’t figure it out myself! Thanx a lot!

Yes this works - BUT one also needs a customized version of GridGraphEditor in order to actually create a graph - otherwise the “add new graph” button for the new type is dimmed and says “no editor found”. I hacked the Grid graph editor …

Ah, true.
You can make a subclass of the editor which simply inherits from the GridGraphEditor and add the attribute to that class if you don’t want to change the source code of the package.