ThePat02 / BehaviourToolkit

A collection of tools for AI Behaviour in the Godot 4 Game Engine!
MIT License
303 stars 12 forks source link

Add the _on_enter() function to the BTBehaviour class for leaf,composite and etc #76

Closed ziengri closed 5 months ago

ziengri commented 5 months ago

I suggest adding the _on_enter(_actor: Node) function to leaf , composite and etc. Since this will make it possible to conveniently change behaviors or parameters in them. Example:every time the behavior tree reaches BTRepeat, I need to write a number from _actor.rep in repetition and the same situation with LeafWait

ThePat02 commented 5 months ago

Well, this would be very similar to tick wouldn't it? Because tick basically is called when the leaf is entered.

Every time the behavior tree reaches BTRepeat, I need to write a number from _actor.rep in repetition and the same situation with LeafWait

I think it would be a better choice to actually create a Leaf that does this and put it before the BTRepeat like this:

BTSequence
   LeafWriter
   BTRepeat

With LeafWriter looking something like this:

class_name LeafWriter extends BTLeaf

@export var target: BTRepeat

func _tick(_delta: float, actor: Node, _blackboard: Blackboard):
    # Adjust according to your needs.  Maybe even make a generic option using more exports for more reusability.
    target.repetitions= actor.reps
    return BTStatus.SUCCESS