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

49 lines
1.2 KiB
ReStructuredText

.. _accessing_nodes:
Accessing nodes in the scene tree
=================================
There are several ways to access nodes in the agent's scene tree.
**🛈 Note:** Agent is the owner of :ref:`BTPlayer<class_BTPlayer>` node.
With ``BBNode`` property
------------------------
.. code:: gdscript
@export var cast_param: BBNode
func _tick(delta) -> Status:
var node: ShapeCast3D = cast_param.get_value(agent, blackboard)
With ``NodePath`` property
--------------------------
.. code:: gdscript
@export var cast_path: NodePath
func _tick(delta) -> Status:
var node: ShapeCast3D = agent.get_node(cast_path)
Using blackboard plan
---------------------
You can :ref:`create a blackboard variable<editing_plan>` in the editor with the type ``NodePath``
and point it to the proper node in the :ref:`BTPlayer<class_BTPlayer>` blackboard plan.
.. code:: gdscript
extends BTCondition
@export var shape_var: String = "shape_cast"
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``.