beehave icon indicating copy to clipboard operation
beehave copied to clipboard

CooldownDecorator and DelayDecorator never call after_run method of their child

Open NectoT opened this issue 1 year ago • 1 comments

Godot version: 4.2.1

To Reproduce Steps to reproduce the behavior:

  1. Create an empty scene with BeehaveTree as root node
  2. Add DelayDecorator or CooldownDecorator as its child
  3. Add ActionLeaf as decorator's child
  4. Extend the ActionLeaf script with the following code:
extends ActionLeaf

func tick(actor: Node, blackboard: Blackboard) -> int:
	return SUCCESS

func after_run(actor: Node, blackboard: Blackboard) -> void:
	print('I finished running')

Expected behavior 'I finished running' message printing out in the output every tick.

Actual behaviour No message is being printed out.

NectoT avatar Mar 11 '24 18:03 NectoT

I've also encountered this. I found it because I have a CooldownDecorator with a SelectorComposite inside of it. Since after_run never gets called on the SelectorComposite after a SUCCESS, it thinks the successful child node is still running, and skips all the children before it.

You can see in this screen capture how part of the subtree keeps lighting up without ever going back to the first child of the decorator's inner sequence: https://github.com/user-attachments/assets/49d3a5f9-6de1-4f33-b802-f30cd7cea3bc

I was able to work around this by subclassing CooldownDecorator and adding a call to after_run when the superclass's tick returns something other than RUNNING. This got things working as expected again.

It also seems that other decorators are not consistently calling before_run and after_run:

  • CooldownDecorator does not call after_run
  • DelayDecorator does not call after_run
  • LimiterDecorator does not call before_run
  • UntilFailDecorator does not call after_run
  • ReapeaterDecorator calls before_run one time, but calls after_run after each repetition that returns SUCCESS or FAILURE (I'm unsure which of these is correct, but I would expect them to match.)

cammerman avatar Aug 26 '24 05:08 cammerman