Make it possible to subclass GraphCollision

In my game, I have some additional walkability check’s I’d like to perform for any position fed into GraphCollision.Check(). For this, I am subclassing GraphCollision to create my own implementation of the Check() method. Unfortunately, in the current release, the method is not marked virtual and hiding it using the new modifier, despite not being a recommended practice, makes Unity still jump into the original method rather than my custom implementation.

So for now I have resorted to directly editing the GraphCollision class to add the virtual modifier to the method, but it’d be great if you could mark the method virtual in your next release, so I don’t have to modify classes inside your project.

Cheers
Philipp

I think a better idea is to subclass the grid graph and override the UpdateNodePositionCollision method. That will give you full control over the node’s walkability and penalty. See also http://arongranberg.com/astar/docs/writing-graph-generators.php in particular you will need to subclass the editor as well (or just add the attribute to the original class) for the graph to show up in the editor.

public override void UpdateNodePositionCollision(GridNode node, int x, int z, bool resetPenalty = true) {
    node.Penalty = 0;
    node.Walkable = true;
    node.WalkableErosion = node.Walkable;
}

That is expected since it does not actually override it. If the method is called while the object is stored in a variable with the base type, then it will still call the base method.