Trying to override _compute_cost() and _estimate_cost() in my AStar2D subclass

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By mason

Hey all,

I’ve created a subclass of AStar2D and tried to override the _compute_cost() and _estimate_cost() functions. I’m trying to make it so A* sees the distance between any two connected nodes as 1. That way, the shortest path is determined only by the number of connections.

Here’s my code: extends Nodeclass HyperAStar2D: extends AStar2D func _compute_cost( - Pastebin.com

It seems to be ignoring the functions I’ve written. Firstly, it fails to calculate the shortest path, and secondly, it doesn’t print “blamo” to the console when computing distance.

Anybody know what I’m doing wrong?

Thanks!

:bust_in_silhouette: Reply From: jgodfrey

What version of Godot are you using? Poking around, it seems that AStar2D didn’t used to allow those methods to be overridden (even though AStar did). However, reading this…

and

…makes me think the necessary changes were implemented in AStar2D and were cherry-picked into both 3.2.3 and 3.2.2.

Ah, perfect. Upgrading fixed the problem. I was running 3.2.1 I think. Thanks for looking into this for me!

mason | 2020-11-19 04:01

:bust_in_silhouette: Reply From: mason

Upgrading fixed the problem. I was running 3.2.1.