@tool
class_name SetTargetFromArea extends ActionLeaf
## Store the first node in the given area on the blackboard.
##
## Returns FAILURE if there is no such node overlapping the given area.
## NOTE: You probably should only use this with areas masked to only have one possible body.

## Key to store the target under.
@export var blackboard_key := "target"

## Area to get target from.
@export var area: Area3D


func tick(_actor: Node, blackboard: Blackboard) -> int:
	var bodies := area.get_overlapping_bodies()
	if not bodies:
		return FAILURE

	blackboard.set_value(blackboard_key, bodies[0])
	return SUCCESS
