Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AStar2D cannot override _estimate_cost or _compute_cost in GDScript #36990

Closed
Adinimys opened this issue Mar 11, 2020 · 4 comments · Fixed by #37039
Closed

AStar2D cannot override _estimate_cost or _compute_cost in GDScript #36990

Adinimys opened this issue Mar 11, 2020 · 4 comments · Fixed by #37039

Comments

@Adinimys
Copy link
Contributor

Godot version : 3.2.1, also present in 4.0

Issue description :
AStar provides a way to override its cost calculation from GDScript. Since AStar2D is a wrapper around it with an AStar astar member there is no way to override the _evaluate_cost() and _compute_cost() inside of it

Steps to reproduce :

`class CustomAStar2D :
extends AStar2D

func _estimate_cost(u, v):
	print("this isn't called")
	var dist = (get_point_position(u) - get_point_position(v)).abs()
	return dist.x + dist.y

func _compute_cost(u, v):
            print("not called either")
	return _estimate_cost(u, v)`

I'm not sure if the best would be to rewrite AStar2D to use its own _solve() which might also slightly improve performance by removing useless calculations. Or completly rewrite AStar2D to not be a wrapper ? Or maybe there is a way to reach astar._estimate_cost() from its wrapper class ?

At least if it's intended that advance uses needing to overwrite those methods should use AStar regardless of 2D/3D, it should be documented here : https://docs.godotengine.org/en/3.2/classes/class_astar2d.html

@bojidar-bg
Copy link
Contributor

CC @Chaosus ( #27237 (comment) ).

@Adinimys
Copy link
Contributor Author

Adinimys commented Mar 12, 2020

Wouldn't the best approach be using templates ? With AStar<Vector3> and AStar<Vector2> exposed as AStar and AStar2D ?
It would also mean that it would be easier to then expand to other datat types to support non-spatial pathfinding (such as in GOAP)

@Chaosus
Copy link
Member

Chaosus commented Mar 14, 2020

You cannot use templates with GDScript so this is not a correct way to solve a problem. I will try to use function pointer instead...

@Adinimys
Copy link
Contributor Author

Thanks ! @Chaosus

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants