Skip to content

Nodes with enter() and exit() methods #118

@lostptr

Description

@lostptr

Overview

We could have enter() and exit() methods for when its necessary to do some setup or cleanup before or after the first and last ticks.
The enter() and exit() methods would be called before the first tick() and after the last, respectively.
For more information, checkout #117

Possible implementation

We create an execute() method inside BeehaveNode to be called by parent nodes only. This method will call enter(), tick() and exit() when needed as well as return the result of tick().

func execute(actor: Node, blackboard: Blackboard) -> int:
	if not _has_entered:
		enter(actor, blackboard)
		_has_entered = true
	
	var result = tick(actor, blackboard)

	if result != RUNNING:
		exit(actor, blackboard)
		_has_entered = false

	return result

This way, we only need to change composite nodes to call execute() instead of tick(). Composites and leaf nodes should never override the execute() method, only tick().

Metadata

Metadata

Assignees

No one assigned

    Labels

    🍯 featureA new addition to this addon.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions