limboai/demo/demo/ai/tasks/get_first_in_group.gd

35 lines
1.0 KiB
GDScript

#*
#* get_first_in_group.gd
#* =============================================================================
#* Copyright 2021-2024 Serhii Snitsaruk
#*
#* Use of this source code is governed by an MIT-style
#* license that can be found in the LICENSE file or at
#* https://opensource.org/licenses/MIT.
#* =============================================================================
#*
@tool
extends BTAction
## Get first node in group and save it to the blackboard.
## Returns FAILURE if group contains 0 nodes.
## Name of the SceneTree group.
@export var group: StringName
## Blackboard variable in which the task will store the acquired node.
@export var output_var: StringName = &"target"
func _generate_name() -> String:
return "GetFirstNodeInGroup \"%s\"%s" % [
group,
LimboUtility.decorate_var(output_var)
]
func _tick(_delta: float) -> Status:
var nodes: Array[Node] = agent.get_tree().get_nodes_in_group(group)
if nodes.size() == 0:
return FAILURE
blackboard.set_var(output_var, nodes[0])
return SUCCESS