Allow objects in BBNode

This commit is contained in:
Serhii Snitsaruk 2023-09-05 10:55:17 +02:00
parent 9ec1675db2
commit fe81b90dc1
4 changed files with 11 additions and 9 deletions

View File

@ -30,12 +30,12 @@ Variant BBNode::get_value(Object *p_agent, const Ref<Blackboard> &p_blackboard,
ERR_FAIL_COND_V_MSG(agent == nullptr, Variant(), "BBNode: p_agent must be a Node."); ERR_FAIL_COND_V_MSG(agent == nullptr, Variant(), "BBNode: p_agent must be a Node.");
return agent->get_node(val); return agent->get_node(val);
} else { } else {
Node *node = Object::cast_to<Node>(val); Object *obj = val;
if (unlikely(node == nullptr && val.get_type() != Variant::NIL)) { if (unlikely(obj == nullptr && val.get_type() != Variant::NIL)) {
WARN_PRINT("BBNode: Unexpected variant type of a blackboard variable."); WARN_PRINT("BBNode: Unexpected variant type of a blackboard variable.");
return p_default; return p_default;
} else { } else {
return node; return obj;
} }
} }
} }

View File

@ -59,7 +59,7 @@ int BTCallMethod::_tick(double p_delta) {
ERR_FAIL_COND_V_MSG(method == StringName(), FAILURE, "BTCallMethod: Method Name is not set."); ERR_FAIL_COND_V_MSG(method == StringName(), FAILURE, "BTCallMethod: Method Name is not set.");
ERR_FAIL_COND_V_MSG(node_param.is_null(), FAILURE, "BTCallMethod: Node parameter is not set."); ERR_FAIL_COND_V_MSG(node_param.is_null(), FAILURE, "BTCallMethod: Node parameter is not set.");
Object *obj = node_param->get_value(get_agent(), get_blackboard()); Object *obj = node_param->get_value(get_agent(), get_blackboard());
ERR_FAIL_COND_V_MSG(obj == nullptr, FAILURE, "BTCallMethod: Failed to get node: " + node_param->to_string()); ERR_FAIL_COND_V_MSG(obj == nullptr, FAILURE, "BTCallMethod: Failed to get object: " + node_param->to_string());
const Variant **argptrs = nullptr; const Variant **argptrs = nullptr;

View File

@ -4,6 +4,8 @@
Node-type parameter to be used with BT tasks. See [BBParam]. Node-type parameter to be used with BT tasks. See [BBParam].
</brief_description> </brief_description>
<description> <description>
Node-type parameter to be used with BT tasks. See [BBParam].
If blackboard is chosen as source, it allows any [Object]-extended type.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>

View File

@ -1,11 +1,11 @@
<?xml version="1.0" encoding="UTF-8" ?> <?xml version="1.0" encoding="UTF-8" ?>
<class name="BTCallMethod" inherits="BTAction" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd"> <class name="BTCallMethod" inherits="BTAction" version="4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../doc/class.xsd">
<brief_description> <brief_description>
BT action that calls a method on the specified [Node]. BT action that calls a method on a specified [Node] or [Object].
</brief_description> </brief_description>
<description> <description>
BTCallMethod calls a method on the specified [Node] and returns [code]SUCCESS[/code]. BTCallMethod calls a method on a specified [Node] or [Object] and returns [code]SUCCESS[/code].
Returns [code]FAILURE[/code] if the action fails executing the node's method. Returns [code]FAILURE[/code] if the action fails executing the method.
</description> </description>
<tutorials> <tutorials>
</tutorials> </tutorials>
@ -14,10 +14,10 @@
Arguments to pass to the method call. Arguments to pass to the method call.
</member> </member>
<member name="method" type="StringName" setter="set_method" getter="get_method" default="&amp;&quot;&quot;"> <member name="method" type="StringName" setter="set_method" getter="get_method" default="&amp;&quot;&quot;">
Node's method that will be called. Method that will be called.
</member> </member>
<member name="node" type="BBNode" setter="set_node_param" getter="get_node_param"> <member name="node" type="BBNode" setter="set_node_param" getter="get_node_param">
Node parameter that will be used to get the node instance. Parameter that will be used to get the node/object instance.
</member> </member>
</members> </members>
</class> </class>