godot-addons/godot-behavior-tree-plugin

Decortor "Repeat Until Succeed" error

Closed this issue · 6 comments

BT_Godot

When tick hits decorator "Repeat Until Succeed" I got "Stack Overflow" Error.
It looks like "Repeat Until Succeed" loops indefinitely without giving time his child to process.

Good catch, i think i need to setup a scene that uses every class to prevent such mistakes.

In script "repeat_until_succeed.gd" is missing 'c' reference in loop:
It is in script "repeat_until_fail.gd". I add it, but instead of crash, game froze. Probably because after that change, loop in decorator is the only thing that is processed.

func tick(tick: Tick) -> int:
	
	# 0..1 children
	for c in get_children():
		
		while true:
			if _execute(tick) == OK:  # Here is missing c.
				return OK
	
	return OK

@Drarch I can't reproduce the error after adding the 'c'. Are you sure that the BehaviorSequence ever returns success? If you want you can share the code of FollowTarget and DistanceToTarget.

No it not always return success. At least not within one frame.
Idea is, that it will follow it's target until it is within a certain distance. So it doesn't need to do anything else in tree until AI get it's target. So I wanted loop only sequence that is in decorator.

FollowTarget only LERPs actor towards target and DistanceToTarget check if target is within certain distance.

@brandonlamb @DagobertDev
I put this action under RepeatUntilSucceed decorator.

extends "res://addons/godot-behavior-tree-plugin/action.gd"

var path_points = PoolVector3Array()

func open(tick: Tick) -> void:
	tick.actor.locomotion.set_movement_speed(tick.actor.run_speed)
	tick.actor.set_raw_motion(Vector2.UP)
	path_points = tick.actor.locomotion.get_path(tick.actor.navigation, tick.actor.transform.origin, Vector3(30, 0, 30))

func tick(tick: Tick) -> int:
	if tick.actor.locomotion.move_to_point(tick.actor.delta_time, path_points):
		return OK
	return ERR_BUSY

But when I play the game, it freeze from beginning. I know it is because of this action under RepeatUntilSucceed.
What's wrong with my code ?

Something is weird for me but not sure.
In Repeat Until Succeed code, there is a while, it doesn't make the game freeze ? (When the behavior should be executed in multiple frames)
@DagobertDev @brandonlamb

Also I don't get why when I return ERR_BUSY, it ignores it and repeat whole the tree (Without using Repeat Until Succeed)