limboai/doc/source/getting-started/accessing-nodes.rst

52 lines
1.5 KiB
ReStructuredText
Raw Normal View History

2024-02-17 22:54:38 +00:00
.. _accessing_nodes:
Accessing nodes in the scene tree
=================================
2024-05-02 17:35:42 +00:00
There are several ways to access nodes in the agent's scene tree from a :ref:`BTTask<class_BTTask>`.
2024-02-17 22:54:38 +00:00
2024-05-02 17:35:42 +00:00
**🛈 Note:** The root node of the agent's scene tree can be accessed with the
:ref:`scene_root<class_BTTask_property_scene_root>` property.
2024-02-18 19:50:09 +00:00
With ``BBNode`` property
------------------------
2024-02-17 22:54:38 +00:00
.. code:: gdscript
2024-02-18 19:50:09 +00:00
@export var cast_param: BBNode
2024-02-17 22:54:38 +00:00
func _tick(delta) -> Status:
2024-05-02 17:35:42 +00:00
var node: ShapeCast3D = cast_param.get_value(scene_root, blackboard)
2024-02-18 19:50:09 +00:00
2024-02-17 22:54:38 +00:00
2024-02-18 19:50:09 +00:00
With ``NodePath`` property
--------------------------
2024-02-17 22:54:38 +00:00
.. code:: gdscript
@export var cast_path: NodePath
2024-02-18 19:50:09 +00:00
func _tick(delta) -> Status:
2024-05-02 17:35:42 +00:00
var node: ShapeCast3D = scene_root.get_node(cast_path)
2024-02-18 19:50:09 +00:00
Using blackboard plan
---------------------
2024-02-17 22:54:38 +00:00
2024-02-18 19:50:09 +00:00
You can :ref:`create a blackboard variable<editing_plan>` in the editor with the type ``NodePath``
2024-05-02 17:35:42 +00:00
and point it to the proper node in the :ref:`BTPlayer<class_BTPlayer>` blackboard plan. By default,
any ``NodePath`` variable will be replaced with the node instance when the blackboard is instantiated
at runtime (see :ref:`BlackboardPlan.prefetch_nodepath_vars<class_BlackboardPlan_property_prefetch_nodepath_vars>`).
2024-02-17 22:54:38 +00:00
.. code:: gdscript
extends BTCondition
@export var shape_var: StringName = &"shape_cast"
2024-02-17 22:54:38 +00:00
func _tick(delta) -> Status:
var shape_cast: ShapeCast3D = blackboard.get_var(shape_var)
The property :ref:`BTPlayer.prefetch_nodepath_vars<class_BTPlayer_property_prefetch_nodepath_vars>` should be set to ``true``.